-
Notifications
You must be signed in to change notification settings - Fork 2
/
switch-chain.spec.ts
43 lines (40 loc) · 1.66 KB
/
switch-chain.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {Observable} from 'rxjs';
import {marbles} from 'rxjs-marbles';
import {switchChain} from './switch-chain';
describe('switchChain', () => {
it('should emit an array of values in reserve order', marbles(m => {
const source = switchChain(
m.cold('a'),
() => m.cold('1'),
() => m.cold('x'),
() => m.cold('z')
);
const result = 'a';
m.expect(source).toBeObservable(result, {a: ['z', 'x', '1', 'a']});
}));
it('should complete if all observables complete', marbles(m => {
const source = switchChain(m.cold('a|'), () => m.cold('1|'));
const result = 'a|';
m.expect(source).toBeObservable(result, {a: ['1', 'a']});
}));
it('should pass previous values to projector function', marbles(m => {
const projector1 = jest.fn<Observable<string>, string[]>(() => m.cold('1'));
const projector2 = jest.fn<Observable<string>, string[]>(() => m.cold('x'));
const projector3 = jest.fn<Observable<string>, string[]>(() => m.cold('z'));
const source = switchChain(
m.cold('a'),
projector1,
projector2,
projector3
);
const result = 'a';
m.expect(source).toBeObservable(result, {a: ['z', 'x', '1', 'a']});
m.flush();
expect(projector1.mock.calls.length).toBe(1);
expect(projector2.mock.calls.length).toBe(1);
expect(projector3.mock.calls.length).toBe(1);
expect(projector1.mock.calls[0]).toEqual(['a']);
expect(projector2.mock.calls[0]).toEqual(['1', 'a']);
expect(projector3.mock.calls[0]).toEqual(['x', '1', 'a']);
}));
});