aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/javascript/src/test_helpers
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/test/javascript/src/test_helpers')
-rw-r--r--actioncable/test/javascript/src/test_helpers/index.coffee5
-rw-r--r--actioncable/test/javascript/src/test_helpers/mock_websocket.coffee21
2 files changed, 26 insertions, 0 deletions
diff --git a/actioncable/test/javascript/src/test_helpers/index.coffee b/actioncable/test/javascript/src/test_helpers/index.coffee
new file mode 100644
index 0000000000..e0d1e412cd
--- /dev/null
+++ b/actioncable/test/javascript/src/test_helpers/index.coffee
@@ -0,0 +1,5 @@
+#= require_self
+#= require_tree .
+
+ActionCable.TestHelpers =
+ testURL: "ws://cable.example.com/"
diff --git a/actioncable/test/javascript/src/test_helpers/mock_websocket.coffee b/actioncable/test/javascript/src/test_helpers/mock_websocket.coffee
new file mode 100644
index 0000000000..b7f86f18f6
--- /dev/null
+++ b/actioncable/test/javascript/src/test_helpers/mock_websocket.coffee
@@ -0,0 +1,21 @@
+#= require mock-socket
+
+NativeWebSocket = window.WebSocket
+
+server = null
+consumer = null
+
+ActionCable.TestHelpers.createConsumer = (url, callback) ->
+ window.WebSocket = MockWebSocket
+ server = new MockServer url
+ consumer = ActionCable.createConsumer(url)
+ callback(consumer, server)
+
+QUnit.testDone ->
+ if consumer?
+ consumer.disconnect()
+
+ if server?
+ server.clients().forEach (client) -> client.close()
+ server.close()
+ window.WebSocket = NativeWebSocket