aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/javascript
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2018-12-02 14:50:05 -0500
committerGitHub <noreply@github.com>2018-12-02 14:50:05 -0500
commit985557b53309152e8483b9e702993e33632d31c9 (patch)
tree17465ef013579d8c9ef6c5e0c4359dd9c416b994 /actioncable/test/javascript
parent730ead9b094c5d639b2463ef82de4a4f6b1ff1e9 (diff)
parent2bb4fdef5efc70327c018e982ff809a29ac6708b (diff)
downloadrails-985557b53309152e8483b9e702993e33632d31c9.tar.gz
rails-985557b53309152e8483b9e702993e33632d31c9.tar.bz2
rails-985557b53309152e8483b9e702993e33632d31c9.zip
Merge pull request #34590 from rmacklin/use-websocket-adapter-in-getState
Replace reference to WebSocket global with ActionCable.adapters.WebSocket
Diffstat (limited to 'actioncable/test/javascript')
-rw-r--r--actioncable/test/javascript/src/test.js1
-rw-r--r--actioncable/test/javascript/src/unit/connection_test.js28
2 files changed, 29 insertions, 0 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/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)
+ })
+ })
+})