-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(sample): add ObservableInput support in notifier * test(sample): added tests for sample's ObservableInput notifier * chore(sample): cleanup unused declaration * Delete index.d.ts * Delete index.d.ts Co-authored-by: Ben Lesh <ben@benlesh.com>
- Loading branch information
1 parent
8f1b976
commit b18c2eb
Showing
2 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,77 @@ | ||
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters