aboutsummaryrefslogblamecommitdiffstats
path: root/actioncable/test/javascript/src/test_helpers/mock_websocket.coffee
blob: b7f86f18f6cf0128f694b72c32addfbf370297a6 (plain) (tree)




















                                                           
#= 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