1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

test: add actual error class to fail message (#4305)

This commit is contained in:
Chris Knight 2020-03-09 21:46:55 +00:00 committed by GitHub
parent 7f591c3783
commit 2115b38fef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -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)) {

View file

@ -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[] => [
"",
"",