forked from ReactiveX/rxjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bufferTimeOrCount-spec.js
124 lines (100 loc) · 4.05 KB
/
bufferTimeOrCount-spec.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* globals describe, it, expect, hot, cold, expectObservable, expectSubscriptions, rxTestScheduler, time */
var Rx = require('../../dist/cjs/Rx');
var Observable = Rx.Observable;
describe('Observable.prototype.bufferTimeOrCount', function () {
it.asDiagram('bufferTimeOrCount(100, 2)')('should emit buffers at interval or count', function () {
var e1 = hot('---a--------c---d-------f--------|');
var subs = '^ !';
var t = time( '----------|');
var count = 2;
var expected = '----------w-----x---------y------(z|)';
var values = {
w: ['a'],
x: ['c','d'],
y: ['f'],
z: []
};
var result = e1.bufferTimeOrCount(t, count, rxTestScheduler);
expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
});
it('should emit buffers but handle source ending with an error', function () {
var e1 = hot('---a--------c---d-------f--------#');
var t = time( '----------|');
var count = 2;
var expected = '----------w-----x---------y------#';
var values = {
w: ['a'],
x: ['c','d'],
y: ['f']
};
var result = e1.bufferTimeOrCount(t, count, rxTestScheduler);
expectObservable(result).toBe(expected, values);
});
it('should emit buffers and allow result to unsubscribed early', function () {
var e1 = hot('--1--^2--3---4---5--6--7---8----9------------|');
var unsub = ' ! ';
var subs = '^ ! ';
var t = time( '----------|');
var expected = '----------a------ ';
var values = {
a: ['2', '3', '4']
};
var result = e1.bufferTimeOrCount(t, 5, rxTestScheduler);
expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
});
it('should not break unsubscription chains when result is unsubscribed explicitly', function () {
var e1 = hot('--1--^2--3---4---5--6--7---8----9------------|');
var subs = '^ ! ';
var t = time( '----------|');
var expected = '----------a------ ';
var unsub = ' ! ';
var values = {
a: ['2', '3', '4']
};
var result = e1
.mergeMap(function (x) { return Observable.of(x); })
.bufferTimeOrCount(t, 5, rxTestScheduler)
.mergeMap(function (x) { return Observable.of(x); });
expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
});
it('should handle empty', function () {
var e1 = cold( '|');
var e1subs = '(^!)';
var expected = '(b|)';
var values = { b: [] };
var t = time('----------|');
var result = e1.bufferTimeOrCount(t, 5, rxTestScheduler);
expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
it('should handle never', function () {
var e1 = cold('-');
var unsub = ' !';
var t = time( '----------|');
var expected = '----------a---------a---------a---------a----';
var result = e1.bufferTimeOrCount(t, 5, rxTestScheduler);
expectObservable(result, unsub).toBe(expected, { a: [] });
});
it('should handle throw', function () {
var e1 = Observable.throw(new Error('haha'));
var expected = '#';
var t = time('----------|');
var result = e1.bufferTimeOrCount(t, 5, rxTestScheduler);
expectObservable(result).toBe(expected, undefined, new Error('haha'));
});
it('should handle errors', function () {
var e1 = hot('---a---b---c---#');
var e1subs = '^ !';
var t = time( '----------|');
var expected = '----------w----#';
var values = {
w: ['a','b']
};
var result = e1.bufferTimeOrCount(t, 5, rxTestScheduler);
expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});