aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/javascript/src/unit/connection_test.js
blob: 9b1a975bfb63ea0c13196c76d7aca653a920959e (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
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)
    })
  })
})