Skip to content

Commit

Permalink
test(sample): added tests for sample's ObservableInput notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymwells committed Nov 1, 2022
1 parent 78409d6 commit 7f78fc0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
4 changes: 1 addition & 3 deletions api_guard/dist/types/operators/index.d.ts
@@ -1,5 +1,3 @@
import { ObservableInput } from "..";

export declare function audit<T>(durationSelector: (value: T) => ObservableInput<any>): MonoTypeOperatorFunction<T>;

export declare function auditTime<T>(duration: number, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
Expand Down Expand Up @@ -241,7 +239,7 @@ export declare function retry<T>(config: RetryConfig): MonoTypeOperatorFunction<
export interface RetryConfig {
count?: number;
delay?: number | ((error: any, retryCount: number) => ObservableInput<any>);
resetOnSuccess?: boolean; b
resetOnSuccess?: boolean;
}

export declare function retryWhen<T>(notifier: (errors: Observable<any>) => Observable<any>): MonoTypeOperatorFunction<T>;
Expand Down
76 changes: 73 additions & 3 deletions spec-dtslint/operators/sample-spec.ts
@@ -1,11 +1,81 @@
import { of } from 'rxjs';
import { sample } from 'rxjs/operators';
import { asInteropObservable } from '../../spec/helpers/interop-helper';

it('should enforce parameter', () => {
const a = of(1, 2, 3).pipe(sample()); // $ExpectError
of(1, 2, 3).pipe(sample()); // $ExpectError
});

it('should accept observable as notifier parameter', () => {
const a = of(1, 2, 3).pipe(sample(of(4))); // $ExpectType Observable<number>
const b = of(1, 2, 3).pipe(sample(of('a'))); // $ExpectType Observable<number>
of(1, 2, 3).pipe(sample(of(4))); // $ExpectType Observable<number>
of(1, 2, 3).pipe(sample(of('a'))); // $ExpectType Observable<number>
});

it('should accept interop observable notifier', () => {
of(1, 2, 3).pipe(sample(asInteropObservable(of(true)))); // $ExpectType Observable<number>
});

it('should accept promise notifier', () => {
of(1, 2, 3).pipe(sample(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(sample(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(sample(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(sample(readableStream)); // $ExpectType Observable<number>
});

it('should enforce types of the notifier', () => {
of(1, 2, 3).pipe(sample(8)); // $ExpectError
});

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

0 comments on commit 7f78fc0

Please sign in to comment.