From d45630b7631b2b1286e8683b7aa2bd795b38b1f4 Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 8 Oct 2020 16:03:17 -0700 Subject: [PATCH] update tests to account for actual RxJS 7 implementation --- packages/kbn-std/src/rxjs_7.test.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/kbn-std/src/rxjs_7.test.ts b/packages/kbn-std/src/rxjs_7.test.ts index 8f0ffe7d7a509..dcc73602613fa 100644 --- a/packages/kbn-std/src/rxjs_7.test.ts +++ b/packages/kbn-std/src/rxjs_7.test.ts @@ -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((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((subscriber) => { + setTimeout(() => { + while (!subscriber.closed) { + subscriber.next(values.shift()!); + } + unsubscribed = subscriber.closed; + }); }); await expect(firstValueFrom(source)).resolves.toMatchInlineSnapshot(`1`);