forked from ReactiveX/rxjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpairwise-spec.ts
103 lines (78 loc) · 2.56 KB
/
pairwise-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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions};
/** @test {pairwise} */
describe('Observable.prototype.pairwise', () => {
asDiagram('pairwise')('should group consecutive emissions as arrays of two', () => {
const e1 = hot('--a--b-c----d--e---|');
const expected = '-----u-v----w--x---|';
const values = {
u: ['a', 'b'],
v: ['b', 'c'],
w: ['c', 'd'],
x: ['d', 'e']
};
const source = (<any>e1).pairwise();
expectObservable(source).toBe(expected, values);
});
it('should pairwise things', () => {
const e1 = hot('--a--^--b--c--d--e--f--g--|');
const e1subs = '^ !';
const expected = '------v--w--x--y--z--|';
const values = {
v: ['b', 'c'],
w: ['c', 'd'],
x: ['d', 'e'],
y: ['e', 'f'],
z: ['f', 'g']
};
const source = (<any>e1).pairwise();
expectObservable(source).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
it('should not emit on single-element streams', () => {
const e1 = hot('-----^--b----|');
const e1subs = '^ !';
const expected = '--------|';
const values = {
};
const source = (<any>e1).pairwise();
expectObservable(source).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
it('should handle mid-stream throw', () => {
const e1 = hot('--a--^--b--c--d--e--#');
const e1subs = '^ !';
const expected = '------v--w--x--#';
const values = {
v: ['b', 'c'],
w: ['c', 'd'],
x: ['d', 'e']
};
const source = (<any>e1).pairwise();
expectObservable(source).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
it('should handle empty', () => {
const e1 = cold('|');
const e1subs = '(^!)';
const expected = '|';
const source = (<any>e1).pairwise();
expectObservable(source).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
it('should handle never', () => {
const e1 = cold('-');
const e1subs = '^';
const expected = '-';
const source = (<any>e1).pairwise();
expectObservable(source).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
it('should handle throw', () => {
const e1 = cold('#');
const e1subs = '(^!)';
const expected = '#';
const source = (<any>e1).pairwise();
expectObservable(source).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});