1 |
|
2 |
|
3 |
|
4 |
|
5 | import createState from './state';
|
6 | import subscribe from './subscribe';
|
7 | import unsubscribe from './unsubscribe';
|
8 |
|
9 | describe('unsubscribe', () => {
|
10 | let state;
|
11 | let id;
|
12 |
|
13 | beforeEach(() => {
|
14 | state = createState();
|
15 |
|
16 | return subscribe(state, 'chain_newHead', 'chain_newHead', [() => void 0]).then((_id) => {
|
17 | id = _id;
|
18 | });
|
19 | });
|
20 |
|
21 | it('fails on unknown ids', () => {
|
22 | return unsubscribe(state, 'chain_newHead', 'chain_newHead', 5).catch((error) => {
|
23 | expect(error.message).toMatch(/Unable to find/);
|
24 | });
|
25 | });
|
26 |
|
27 | it('unsubscribes successfully', () => {
|
28 | return unsubscribe(state, 'chain_newHead', 'chain_newHead', id);
|
29 | });
|
30 |
|
31 | it('fails on double unsubscribe', () => {
|
32 | return unsubscribe(state, 'chain_newHead', 'chain_newHead', id)
|
33 | .then(() => unsubscribe(state, id))
|
34 | .catch((error) => {
|
35 | expect(error.message).toMatch(/Unable to find/);
|
36 | });
|
37 | });
|
38 |
|
39 | it('clears the subscriptions', () => {
|
40 | return unsubscribe(state, 'chain_newHead', 'chain_newHead', id).then(() => {
|
41 | expect(state.subscriptionMap[id]).not.toBeDefined();
|
42 | expect(state.subscriptions['chain_newHead'].callbacks[id]).not.toBeDefined();
|
43 | });
|
44 | });
|
45 | });
|