1 |
|
2 |
|
3 |
|
4 |
|
5 | import { mockWs, TEST_WS_URL } from '../../test/mockWs';
|
6 |
|
7 | import Ws from './index';
|
8 |
|
9 | let ws;
|
10 | let mock;
|
11 |
|
12 | function createMock (requests) {
|
13 | mock = mockWs(requests);
|
14 | }
|
15 |
|
16 | function createWs (autoConnect) {
|
17 | ws = new Ws(TEST_WS_URL, autoConnect);
|
18 |
|
19 | return ws;
|
20 | }
|
21 |
|
22 | describe('subscribe', () => {
|
23 | let globalWs;
|
24 |
|
25 | beforeEach(() => {
|
26 | globalWs = global.WebSocket;
|
27 | });
|
28 |
|
29 | afterEach(() => {
|
30 | global.WebSocket = globalWs;
|
31 |
|
32 | if (mock) {
|
33 | mock.done();
|
34 | mock = null;
|
35 | }
|
36 | });
|
37 |
|
38 | it('adds subscriptions', () => {
|
39 | createMock([{
|
40 | id: 1,
|
41 | method: 'test_sub',
|
42 | reply: {
|
43 | result: 1
|
44 | }
|
45 | }]);
|
46 |
|
47 | return createWs()
|
48 | .subscribe('test_sub', [], () => {})
|
49 | .then((id) => {
|
50 | expect(id).toEqual(1);
|
51 | });
|
52 | });
|
53 | });
|