1 |
|
2 |
|
3 |
|
4 |
|
5 | import createState from './state';
|
6 | import subscribe from './subscribe';
|
7 |
|
8 | describe('subscribe', () => {
|
9 | let state;
|
10 |
|
11 | beforeEach(() => {
|
12 | state = createState();
|
13 | });
|
14 |
|
15 | it('fails on unknown methods', () => {
|
16 | return subscribe(state, 'test', 'test_notFound').catch((error) => {
|
17 | expect(error.message).toMatch(/Invalid method 'test_notFound'/);
|
18 | });
|
19 | });
|
20 |
|
21 | it('returns a subscription id', () => {
|
22 | return subscribe(state, 'chain_newHead', 'chain_newHead', [() => void 0]).then((id) => {
|
23 | expect(id).toEqual(state.subscriptionId);
|
24 | });
|
25 | });
|
26 |
|
27 | it('stores the mapping values', () => {
|
28 | const cb = () => void 0;
|
29 |
|
30 | return subscribe(state, 'chain_newHead', 'chain_newHead', [cb]).then((id) => {
|
31 | expect(state.subscriptionMap[id]).toEqual('chain_newHead');
|
32 | expect(state.subscriptions['chain_newHead'].callbacks[id]).toEqual(cb);
|
33 | });
|
34 | });
|
35 |
|
36 | it('calls back with the last known value', (done) => {
|
37 | state.subscriptions['chain_newHead'].lastValue = 'testValue';
|
38 |
|
39 | subscribe(state, 'chain_newHead', 'chain_newHead', [(_, value) => {
|
40 | expect(value).toEqual('testValue');
|
41 | done();
|
42 | }]);
|
43 | });
|
44 | });
|