diff options
Diffstat (limited to 'actioncable/test')
5 files changed, 37 insertions, 18 deletions
diff --git a/actioncable/test/javascript/src/test.js b/actioncable/test/javascript/src/test.js index 1fca7ab4d3..eea1c0a408 100644 --- a/actioncable/test/javascript/src/test.js +++ b/actioncable/test/javascript/src/test.js @@ -1,5 +1,6 @@ import "./test_helpers/index" import "./unit/action_cable_test" +import "./unit/connection_test" import "./unit/consumer_test" import "./unit/subscription_test" import "./unit/subscriptions_test" diff --git a/actioncable/test/javascript/src/test_helpers/consumer_test_helper.js b/actioncable/test/javascript/src/test_helpers/consumer_test_helper.js index f1abea331b..d1dabc9fc4 100644 --- a/actioncable/test/javascript/src/test_helpers/consumer_test_helper.js +++ b/actioncable/test/javascript/src/test_helpers/consumer_test_helper.js @@ -1,5 +1,5 @@ import { WebSocket as MockWebSocket, Server as MockServer } from "mock-socket" -import ActionCable from "../../../../app/javascript/action_cable/index" +import * as ActionCable from "../../../../app/javascript/action_cable/index" import {defer, testURL} from "./index" export default function(name, options, callback) { @@ -14,7 +14,7 @@ export default function(name, options, callback) { return QUnit.test(name, function(assert) { const doneAsync = assert.async() - ActionCable.WebSocket = MockWebSocket + ActionCable.adapters.WebSocket = MockWebSocket const server = new MockServer(options.url) const consumer = ActionCable.createConsumer(options.url) diff --git a/actioncable/test/javascript/src/test_helpers/index.js b/actioncable/test/javascript/src/test_helpers/index.js index 5fa46c21ae..0cd4e260b3 100644 --- a/actioncable/test/javascript/src/test_helpers/index.js +++ b/actioncable/test/javascript/src/test_helpers/index.js @@ -1,4 +1,4 @@ -import ActionCable from "../../../../app/javascript/action_cable/index" +import * as ActionCable from "../../../../app/javascript/action_cable/index" export const testURL = "ws://cable.example.com/" @@ -6,5 +6,5 @@ export function defer(callback) { setTimeout(callback, 1) } -const originalWebSocket = ActionCable.WebSocket -QUnit.testDone(() => ActionCable.WebSocket = originalWebSocket) +const originalWebSocket = ActionCable.adapters.WebSocket +QUnit.testDone(() => ActionCable.adapters.WebSocket = originalWebSocket) diff --git a/actioncable/test/javascript/src/unit/action_cable_test.js b/actioncable/test/javascript/src/unit/action_cable_test.js index 8847d87545..daad900aca 100644 --- a/actioncable/test/javascript/src/unit/action_cable_test.js +++ b/actioncable/test/javascript/src/unit/action_cable_test.js @@ -1,4 +1,4 @@ -import ActionCable from "../../../../app/javascript/action_cable/index" +import * as ActionCable from "../../../../app/javascript/action_cable/index" import {testURL} from "../test_helpers/index" const {module, test} = QUnit @@ -7,23 +7,13 @@ module("ActionCable", () => { module("Adapters", () => { module("WebSocket", () => { test("default is window.WebSocket", assert => { - assert.equal(ActionCable.WebSocket, window.WebSocket) - }) - - test("configurable", assert => { - ActionCable.WebSocket = "" - assert.equal(ActionCable.WebSocket, "") + assert.equal(ActionCable.adapters.WebSocket, window.WebSocket) }) }) module("logger", () => { test("default is window.console", assert => { - assert.equal(ActionCable.logger, window.console) - }) - - test("configurable", assert => { - ActionCable.logger = "" - assert.equal(ActionCable.logger, "") + assert.equal(ActionCable.adapters.logger, window.console) }) }) }) diff --git a/actioncable/test/javascript/src/unit/connection_test.js b/actioncable/test/javascript/src/unit/connection_test.js new file mode 100644 index 0000000000..9b1a975bfb --- /dev/null +++ b/actioncable/test/javascript/src/unit/connection_test.js @@ -0,0 +1,28 @@ +import * as ActionCable from "../../../../app/javascript/action_cable/index" + +const {module, test} = QUnit + +module("ActionCable.Connection", () => { + module("#getState", () => { + test("uses the configured WebSocket adapter", assert => { + ActionCable.adapters.WebSocket = { foo: 1, BAR: "42" } + const connection = new ActionCable.Connection({}) + connection.webSocket = {} + connection.webSocket.readyState = 1 + assert.equal(connection.getState(), "foo") + connection.webSocket.readyState = "42" + assert.equal(connection.getState(), "bar") + }) + }) + + module("#open", () => { + test("uses the configured WebSocket adapter", assert => { + const FakeWebSocket = function() {} + ActionCable.adapters.WebSocket = FakeWebSocket + const connection = new ActionCable.Connection({}) + connection.monitor = { start() {} } + connection.open() + assert.equal(connection.webSocket instanceof FakeWebSocket, true) + }) + }) +}) |