UNPKG

777 BJavaScriptView Raw
1// Copyright 2017-2018 @polkadot/api-provider authors & contributors
2// This software may be modified and distributed under the terms
3// of the ISC license. See the LICENSE file for details.
4
5import { mockWs, TEST_WS_URL } from '../../test/mockWs';
6
7import Ws from './index';
8
9describe('onConnect', () => {
10 let mock;
11
12 beforeEach(() => {
13 mock = mockWs([]);
14 });
15
16 afterEach(() => {
17 if (mock) {
18 mock.done();
19 mock = null;
20 }
21 });
22
23 it('sets up the on* handlers', () => {
24 const ws = new Ws(TEST_WS_URL, false);
25
26 ws.connect();
27
28 expect(ws.websocket.onclose[0]).toBeDefined();
29 expect(ws.websocket.onerror[0]).toBeDefined();
30 expect(ws.websocket.onmessage[0]).toBeDefined();
31 expect(ws.websocket.onopen[0]).toBeDefined();
32 });
33});