Skip to content

Commit

Permalink
test: add shareReplay firehose-source test (#6376)
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed May 10, 2021
1 parent e0b5acb commit f1b95cc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/operators/shareReplay-spec.ts
Expand Up @@ -347,6 +347,24 @@ describe('shareReplay', () => {
});
});

it('should stop listening to a synchronous observable when unsubscribed', () => {
const sideEffects: number[] = [];
const synchronousObservable = new Observable<number>((subscriber) => {
// This will check to see if the subscriber was closed on each loop
// when the unsubscribe hits (from the `take`), it should be closed
for (let i = 0; !subscriber.closed && i < 10; i++) {
sideEffects.push(i);
subscriber.next(i);
}
});

synchronousObservable.pipe(shareReplay({ refCount: true }), take(3)).subscribe(() => {
/* noop */
});

expect(sideEffects).to.deep.equal([0, 1, 2]);
});

const FinalizationRegistry = (global as any).FinalizationRegistry;
if (FinalizationRegistry) {
it('should not leak the subscriber for sync sources', (done) => {
Expand Down

0 comments on commit f1b95cc

Please sign in to comment.