diff options
Diffstat (limited to 'std/testing')
-rw-r--r-- | std/testing/asserts.ts | 6 | ||||
-rw-r--r-- | std/testing/asserts_test.ts | 18 |
2 files changed, 21 insertions, 3 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts index d562447c8..1c6dfff19 100644 --- a/std/testing/asserts.ts +++ b/std/testing/asserts.ts @@ -315,9 +315,9 @@ export function assertThrows( fn(); } catch (e) { if (ErrorClass && !(Object.getPrototypeOf(e) === ErrorClass.prototype)) { - msg = `Expected error to be instance of "${ErrorClass.name}"${ - msg ? `: ${msg}` : "." - }`; + msg = `Expected error to be instance of "${ErrorClass.name}", but was "${ + e.constructor.name + }"${msg ? `: ${msg}` : "."}`; throw new AssertionError(msg); } if (msgIncludes && !e.message.includes(msgIncludes)) { diff --git a/std/testing/asserts_test.ts b/std/testing/asserts_test.ts index 3a846417a..558ce1578 100644 --- a/std/testing/asserts_test.ts +++ b/std/testing/asserts_test.ts @@ -230,6 +230,24 @@ test(function testingAssertFail(): void { ); }); +test(function testingAssertFailWithWrongErrorClass(): void { + assertThrows( + (): void => { + //This next assertThrows will throw an AssertionError due to the wrong + //expected error class + assertThrows( + (): void => { + fail("foo"); + }, + Error, + "Failed assertion: foo" + ); + }, + AssertionError, + `Expected error to be instance of "Error", but was "AssertionError"` + ); +}); + const createHeader = (): string[] => [ "", "", |