diff --git a/src/testing/internal/ObservableStream.ts b/src/testing/internal/ObservableStream.ts index 57bdb229b5..ad5d7c0517 100644 --- a/src/testing/internal/ObservableStream.ts +++ b/src/testing/internal/ObservableStream.ts @@ -33,10 +33,16 @@ export class ObservableStream { } take({ timeout = 100 }: TakeOptions = {}) { - return new Promise>((resolve, reject) => { - this.reader.read().then((result) => resolve(result.value!)); - setTimeout(reject, timeout, new Error("Timeout waiting for next event")); - }); + return Promise.race([ + this.reader.read().then((result) => result.value!), + new Promise>((_, reject) => { + setTimeout( + reject, + timeout, + new Error("Timeout waiting for next event") + ); + }), + ]); } unsubscribe() { @@ -57,7 +63,6 @@ export class ObservableStream { async takeComplete(options?: TakeOptions): Promise { const event = await this.take(options); - validateEquals(event, { type: "complete" }); } }