UNPKG

880 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
9let ws;
10let mock;
11
12function createWs (requests, autoConnect) {
13 mock = mockWs(requests);
14 ws = new Ws(TEST_WS_URL, autoConnect);
15
16 return ws;
17}
18
19describe('onOpen', () => {
20 afterEach(() => {
21 if (mock) {
22 mock.done();
23 mock = null;
24 }
25 });
26
27 it('sends messages when connected', () => {
28 const ws = createWs([{
29 id: 1,
30 method: 'test_queue',
31 reply: {
32 result: 'ok'
33 }
34 }], false);
35 const sendPromise = ws.send('test_queue', []);
36
37 ws.connect();
38
39 return sendPromise.then((result) => {
40 expect(result).toEqual('ok');
41 });
42 });
43});