aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/javascript/src/unit/consumer_test.coffee
blob: d8b1450ad87ac39060419824715b510c13a03120 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{module, test} = QUnit
{testURL, createConsumer} = ActionCable.TestHelpers

module "ActionCable.Consumer", ->
  test "#connect", (assert) ->
    done = assert.async()

    createConsumer testURL, (consumer, server) ->
      server.on "connection", ->
        clients = server.clients()
        assert.equal clients.length, 1
        assert.equal clients[0].readyState, WebSocket.OPEN
        done()

      consumer.connect()

  test "#disconnect", (assert) ->
    done = assert.async()

    createConsumer testURL, (consumer, server) ->
      server.on "connection", ->
        clients = server.clients()
        assert.equal clients.length, 1

        clients[0].addEventListener "close", (event) ->
          assert.equal event.type, "close"
          done()

        consumer.disconnect()

      consumer.connect()