Skip to content

Commit

Permalink
test(retryWhen): added tests for ObservableInput notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymwells committed Dec 15, 2022
1 parent d4c8a12 commit 0a70bd8
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions spec-dtslint/operators/retryWhen-spec.ts
@@ -1,5 +1,6 @@
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>
Expand All @@ -13,10 +14,71 @@ 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', () => {
const o = of(1, 2, 3).pipe(retryWhen(() => 8)); // $ExpectError
of(1, 2, 3).pipe(retryWhen(() => 8)); // $ExpectError
});

it('should be deprecated', () => {
const o = of(1, 2, 3).pipe(retryWhen(() => of(true))); // $ExpectDeprecation
of(1, 2, 3).pipe(retryWhen(() => of(true))); // $ExpectDeprecation
});

0 comments on commit 0a70bd8

Please sign in to comment.