-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathinference-spec.ts
46 lines (42 loc) · 1.74 KB
/
inference-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
import '../iterablehelpers';
import '../asynciterablehelpers.js';
import { PassThrough } from 'stream';
import { of } from 'ix/iterable/index.js';
import { map } from 'ix/iterable/operators/index.node.js';
const TEST_DOM_STREAMS = process.env.TEST_DOM_STREAMS === 'true';
const TEST_NODE_STREAMS = process.env.TEST_NODE_STREAMS === 'true';
describe('Iterable type inference', () => {
test('#pipe type inference is correct with one operator', () => {
const source = of(0, 1, 2).pipe(map((x) => x + 1));
expect(source).toEqualStream([1, 2, 3]);
});
test('#pipe type inference is correct with two operators', () => {
const source = of(0, 1, 2).pipe(
map((x) => x + 1),
map((x) => x + 1)
);
expect(source).toEqualStream([2, 3, 4]);
});
if (TEST_NODE_STREAMS) {
test('#pipe type inference is correct with writable stream', () => {
const source = of(0, 1, 2).pipe(new PassThrough({ objectMode: true }));
expect(source).toEqualStream([0, 1, 2]);
});
test('#pipe type inference is correct with writable stream and pipe options', () => {
const source = of(0, 1, 2).pipe(new PassThrough({ objectMode: true }), { end: true });
expect(source).toEqualStream([0, 1, 2]);
});
}
if (TEST_DOM_STREAMS) {
test('#pipeThrough type inference is correct with writable stream', () => {
const source = of(0, 1, 2).pipeThrough(new TransformStream<number, number>());
expect(source).toEqualStream([0, 1, 2]);
});
test('#pipeThrough type inference is correct with writable stream and pipe options', () => {
const source = of(0, 1, 2).pipeThrough(new TransformStream<number, number>(), {
preventClose: false,
});
expect(source).toEqualStream([0, 1, 2]);
});
}
});