From 5955556a5b37a5fceb3054a2bd4f80fd665d0efe Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Wed, 21 Jul 2021 20:05:02 +0200 Subject: [PATCH 1/2] fix: assertThrowsAsync always reporting Error instead of ErrorClass --- testing/asserts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/asserts.ts b/testing/asserts.ts index fb96a08dacff..5a8adae9282a 100644 --- a/testing/asserts.ts +++ b/testing/asserts.ts @@ -641,7 +641,7 @@ export async function assertThrowsAsync( } if (ErrorClass && !(e instanceof ErrorClass)) { msg = - `Expected error to be instance of "${ErrorClass.name}", but got "${e.name}"${ + `Expected error to be instance of "${ErrorClass.name}", but was "${e.constructor.name}"${ msg ? `: ${msg}` : "." }`; throw new AssertionError(msg); From 6fae3d8e86f90b562a19015494244006a1f49ad4 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Sun, 25 Jul 2021 19:51:53 +0200 Subject: [PATCH 2/2] test: add test case --- testing/asserts_test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/testing/asserts_test.ts b/testing/asserts_test.ts index ab22cf805c22..ffda682bb361 100644 --- a/testing/asserts_test.ts +++ b/testing/asserts_test.ts @@ -1039,3 +1039,18 @@ Deno.test("Assert Throws Async Parent Error", () => { "Fail!", ); }); + +Deno.test("Assert Throws Async promise rejected with custom Error", async () => { + class CustomError extends Error {} + class AnotherCustomError extends Error {} + await assertThrowsAsync( + () => + assertThrowsAsync( + () => Promise.reject(new AnotherCustomError("failed")), + CustomError, + "fail", + ), + AssertionError, + 'Expected error to be instance of "CustomError", but was "AnotherCustomError".', + ); +});