|
1 | 1 | import { of } from 'rxjs';
|
2 | 2 | import { sample } from 'rxjs/operators';
|
| 3 | +import { asInteropObservable } from '../../spec/helpers/interop-helper'; |
3 | 4 |
|
4 | 5 | it('should enforce parameter', () => {
|
5 |
| - const a = of(1, 2, 3).pipe(sample()); // $ExpectError |
| 6 | + of(1, 2, 3).pipe(sample()); // $ExpectError |
6 | 7 | });
|
7 | 8 |
|
8 | 9 | it('should accept observable as notifier parameter', () => {
|
9 |
| - const a = of(1, 2, 3).pipe(sample(of(4))); // $ExpectType Observable<number> |
10 |
| - const b = of(1, 2, 3).pipe(sample(of('a'))); // $ExpectType Observable<number> |
| 10 | + of(1, 2, 3).pipe(sample(of(4))); // $ExpectType Observable<number> |
| 11 | + of(1, 2, 3).pipe(sample(of('a'))); // $ExpectType Observable<number> |
| 12 | +}); |
| 13 | + |
| 14 | +it('should accept interop observable notifier', () => { |
| 15 | + of(1, 2, 3).pipe(sample(asInteropObservable(of(true)))); // $ExpectType Observable<number> |
| 16 | +}); |
| 17 | + |
| 18 | +it('should accept promise notifier', () => { |
| 19 | + of(1, 2, 3).pipe(sample(Promise.resolve(true))); // $ExpectType Observable<number> |
| 20 | +}); |
| 21 | + |
| 22 | +it('should async iterable notifier', () => { |
| 23 | + const asyncRange = { |
| 24 | + from: 1, |
| 25 | + to: 2, |
| 26 | + [Symbol.asyncIterator]() { |
| 27 | + return { |
| 28 | + current: this.from, |
| 29 | + last: this.to, |
| 30 | + async next() { |
| 31 | + await Promise.resolve(); |
| 32 | + const done = (this.current > this.last); |
| 33 | + return { |
| 34 | + done, |
| 35 | + value: done ? this.current++ : undefined |
| 36 | + }; |
| 37 | + } |
| 38 | + }; |
| 39 | + } |
| 40 | + }; |
| 41 | + of(1, 2, 3).pipe(sample(asyncRange)); // $ExpectType Observable<number> |
| 42 | +}); |
| 43 | + |
| 44 | +it('should accept iterable notifier', () => { |
| 45 | + const syncRange = { |
| 46 | + from: 1, |
| 47 | + to: 2, |
| 48 | + [Symbol.iterator]() { |
| 49 | + return { |
| 50 | + current: this.from, |
| 51 | + last: this.to, |
| 52 | + next() { |
| 53 | + const done = (this.current > this.last); |
| 54 | + return { |
| 55 | + done, |
| 56 | + value: done ? this.current++ : undefined |
| 57 | + }; |
| 58 | + } |
| 59 | + }; |
| 60 | + } |
| 61 | + }; |
| 62 | + of(1, 2, 3).pipe(sample(syncRange)); // $ExpectType Observable<number> |
| 63 | +}); |
| 64 | + |
| 65 | +it('should accept readable stream notifier', () => { |
| 66 | + const readableStream = new ReadableStream<string>({ |
| 67 | + pull(controller) { |
| 68 | + controller.enqueue('x'); |
| 69 | + controller.close(); |
| 70 | + }, |
| 71 | + }); |
| 72 | + of(1, 2, 3).pipe(sample(readableStream)); // $ExpectType Observable<number> |
| 73 | +}); |
| 74 | + |
| 75 | +it('should enforce types of the notifier', () => { |
| 76 | + of(1, 2, 3).pipe(sample(8)); // $ExpectError |
11 | 77 | });
|
0 commit comments