Skip to content

Commit

Permalink
update tests to account for actual RxJS 7 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Oct 8, 2020
1 parent 0c40b3e commit d45630b
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/kbn-std/src/rxjs_7.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,34 @@ describe('firstValueFrom()', () => {
);
});

it('unsubscribes from the source observable after first notification', async () => {
it('does not unsubscribe from the source observable that emits synchronously', async () => {
const values = [1, 2, 3, 4];
let unsubscribed = false;
const source = new Rx.Observable<number>((subscriber) => {
while (!subscriber.closed) {
while (!subscriber.closed && values.length) {
subscriber.next(values.shift()!);
}
unsubscribed = subscriber.closed;
subscriber.complete();
});

await expect(firstValueFrom(source)).resolves.toMatchInlineSnapshot(`1`);
if (unsubscribed) {
throw new Error('expected source to not be unsubscribed');
}
expect(values).toEqual([]);
});

it('unsubscribes from the source observable after first async notification', async () => {
const values = [1, 2, 3, 4];
let unsubscribed = false;
const source = new Rx.Observable<number>((subscriber) => {
setTimeout(() => {
while (!subscriber.closed) {
subscriber.next(values.shift()!);
}
unsubscribed = subscriber.closed;
});
});

await expect(firstValueFrom(source)).resolves.toMatchInlineSnapshot(`1`);
Expand Down

0 comments on commit d45630b

Please sign in to comment.