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 createWs (requests, autoConnect) {
|
13 | mock = mockWs(requests);
|
14 | ws = new Ws(TEST_WS_URL, autoConnect);
|
15 |
|
16 | return ws;
|
17 | }
|
18 |
|
19 | describe('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 | });
|