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:
parent
7f591c3783
commit
2115b38fef
2 changed files with 21 additions and 3 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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[] => [
|
||||
"",
|
||||
"",
|
||||
|
|
Loading…
Reference in a new issue