-
Notifications
You must be signed in to change notification settings - Fork 3k
/
distinct-spec.ts
94 lines (82 loc) · 2.72 KB
/
distinct-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
import { of } from 'rxjs';
import { asInteropObservable } from '../../spec/helpers/interop-helper';
import { distinct } from 'rxjs/operators';
import { ReadableStreamLike } from '../../src/internal/types';
it('should infer correctly', () => {
const o = of(1, 2, 3).pipe(distinct()); // $ExpectType Observable<number>
});
it('should accept a keySelector', () => {
interface Person { name: string; }
const o = of({ name: 'Tim' } as Person).pipe(distinct(person => person.name)); // $ExpectType Observable<Person>
});
it('should accept observable flush', () => {
const o = of(1, 2, 3).pipe(distinct(n => n, of('t', 'i', 'm'))); // $ExpectType Observable<number>
});
it('should accept interop observable flush', () => {
of(1, 2, 3).pipe(distinct(n => n, asInteropObservable(of('t', 'i', 'm')))); // $ExpectType Observable<number>
});
it('should accept array-like flush', () => {
of(1, 2, 3).pipe(distinct(n => n, [1,2,3])); // $ExpectType Observable<number>
});
it('should accept promise flush', () => {
of(1, 2, 3).pipe(distinct(n => n, Promise.resolve())); // $ExpectType Observable<number>
});
it('should accept async iterable flush', () => {
const asyncRange = {
from: 1,
to: 2,
[Symbol.asyncIterator]() {
return {
current: this.from,
last: this.to,
async next() {
await Promise.resolve();
const done = (this.current > this.last);
return {
done,
value: done ? this.current++ : undefined
};
}
};
}
};
of(1, 2, 3).pipe(distinct(n => n, asyncRange)); // $ExpectType Observable<number>
});
it('should accept iterable flush', () => {
const syncRange = {
from: 1,
to: 2,
[Symbol.iterator]() {
return {
current: this.from,
last: this.to,
next() {
const done = (this.current > this.last);
return {
done,
value: done ? this.current++ : undefined
};
}
};
}
};
of(1, 2, 3).pipe(distinct(n => n, syncRange)); // $ExpectType Observable<number>
});
it('should accept readable stream flush', () => {
const readable: ReadableStreamLike<string> = new ReadableStream<string>({
pull(controller) {
controller.enqueue('x');
controller.close();
},
});
of(1, 2, 3).pipe(distinct(n => n, readable)); // $ExpectType Observable<number>
});
it('should error with unsupported flush', () => {
of(1, 2, 3).pipe(distinct(n => n, {})); // $ExpectError
});
it('should enforce types', () => {
const o = of(1, 2, 3).pipe(distinct('F00D')); // $ExpectError
});
it('should enforce types of keySelector', () => {
const o = of<{ id: string; }>({id: 'F00D'}).pipe(distinct(item => item.foo)); // $ExpectError
});