From 490d2a5ca1acff12ca0f47db8d654848046e3149 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 16 Jun 2020 02:03:07 +1000 Subject: fix: MuxAsyncIterator throws muxed errors (#6295) Fixes #5260 --- std/async/mux_async_iterator_test.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'std/async/mux_async_iterator_test.ts') diff --git a/std/async/mux_async_iterator_test.ts b/std/async/mux_async_iterator_test.ts index 7017a4eba..5ca28903b 100644 --- a/std/async/mux_async_iterator_test.ts +++ b/std/async/mux_async_iterator_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts"; import { MuxAsyncIterator } from "./mux_async_iterator.ts"; // eslint-disable-next-line require-await @@ -16,6 +16,12 @@ async function* gen456(): AsyncIterableIterator { yield 6; } +// eslint-disable-next-line require-await +async function* genThrows(): AsyncIterableIterator { + yield 7; + throw new Error("something went wrong"); +} + Deno.test("[async] MuxAsyncIterator", async function (): Promise { const mux = new MuxAsyncIterator(); mux.add(gen123()); @@ -26,3 +32,22 @@ Deno.test("[async] MuxAsyncIterator", async function (): Promise { } assertEquals(results.size, 6); }); + +Deno.test({ + name: "[async] MuxAsyncIterator throws", + async fn() { + const mux = new MuxAsyncIterator(); + mux.add(gen123()); + mux.add(genThrows()); + const results = new Set(); + await assertThrowsAsync( + async () => { + for await (const value of mux) { + results.add(value); + } + }, + Error, + "something went wrong" + ); + }, +}); -- cgit v1.2.3