forked from ReactiveX/rxjs
/
retryWhen-spec.ts
84 lines (74 loc) · 2.34 KB
/
retryWhen-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
import { of } from 'rxjs';
import { retryWhen } from 'rxjs/operators';
import { asInteropObservable } from '../../spec/helpers/interop-helper';
it('should infer correctly', () => {
const o = of(1, 2, 3).pipe(retryWhen(errors => errors)); // $ExpectType Observable<number>
});
it('should infer correctly when the error observable has a different type', () => {
const o = of(1, 2, 3).pipe(retryWhen(retryWhen(errors => of('a', 'b', 'c')))); // $ExpectType Observable<number>
});
it('should enforce types', () => {
const o = of(1, 2, 3).pipe(retryWhen()); // $ExpectError
});
it('should accept interop observable notifier', () => {
of(1, 2, 3).pipe(retryWhen(() => asInteropObservable(of(true)))); // $ExpectType Observable<number>
});
it('should accept promise notifier', () => {
of(1, 2, 3).pipe(retryWhen(() => Promise.resolve(true))); // $ExpectType Observable<number>
});
it('should async iterable notifier', () => {
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(retryWhen(() => asyncRange)); // $ExpectType Observable<number>
});
it('should accept iterable notifier', () => {
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(retryWhen(() => syncRange)); // $ExpectType Observable<number>
});
it('should accept readable stream notifier', () => {
const readableStream = new ReadableStream<string>({
pull(controller) {
controller.enqueue('x');
controller.close();
},
});
of(1, 2, 3).pipe(retryWhen(() => readableStream)); // $ExpectType Observable<number>
});
it('should enforce types of the notifier', () => {
of(1, 2, 3).pipe(retryWhen(() => 8)); // $ExpectError
});
it('should be deprecated', () => {
of(1, 2, 3).pipe(retryWhen(() => of(true))); // $ExpectDeprecation
});