diff options
Diffstat (limited to 'actioncable/test/javascript/src/test_helpers/mock_websocket.coffee')
-rw-r--r-- | actioncable/test/javascript/src/test_helpers/mock_websocket.coffee | 21 |
1 files changed, 21 insertions, 0 deletions
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 |