-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
test.js
62 lines (52 loc) · 991 Bytes
/
test.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
const test = require('tape');
const {
forEach,
interval,
fromIter,
take,
map,
filter,
pipe
} = require('./index');
test('it works with observables', t => {
t.plan(12);
const expected = [1, 3, 5, 7, 9];
pipe(
interval(10),
map(x => x + 1),
filter(x => x % 2),
take(5),
forEach(x => {
t.true(expected.length > 0);
const e = expected.shift();
t.equals(x, e);
})
);
setTimeout(() =>{
t.pass('nothing else happens');
t.equals(expected.length, 0);
t.end();
}, 300);
});
test('it works with iterables', t => {
t.plan(11);
const expected = [10, 10.25, 10.5, 10.75, 11];
function* range(from, to) {
let i = from;
while (i <= to) {
yield i;
i++;
}
}
pipe(
fromIter(range(40, 99)),
take(5),
map(x => x / 4),
forEach(x => {
t.true(expected.length > 0);
const e = expected.shift();
t.equals(x, e);
})
);
t.equals(expected.length, 0);
});