mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 12:16:11 -05:00
fix(std/testing): assertThrows inheritance (#6623)
This commit is contained in:
parent
fe8399973a
commit
9eca71caa1
2 changed files with 24 additions and 4 deletions
|
@ -394,7 +394,7 @@ export function assertThrows<T = void>(
|
|||
if (e instanceof Error === false) {
|
||||
throw new AssertionError("A non-Error object was thrown.");
|
||||
}
|
||||
if (ErrorClass && !(Object.getPrototypeOf(e) === ErrorClass.prototype)) {
|
||||
if (ErrorClass && !(e instanceof ErrorClass)) {
|
||||
msg = `Expected error to be instance of "${ErrorClass.name}", but was "${
|
||||
e.constructor.name
|
||||
}"${msg ? `: ${msg}` : "."}`;
|
||||
|
@ -438,7 +438,7 @@ export async function assertThrowsAsync<T = void>(
|
|||
if (e instanceof Error === false) {
|
||||
throw new AssertionError("A non-Error object was thrown or rejected.");
|
||||
}
|
||||
if (ErrorClass && !(Object.getPrototypeOf(e) === ErrorClass.prototype)) {
|
||||
if (ErrorClass && !(e instanceof ErrorClass)) {
|
||||
msg = `Expected error to be instance of "${ErrorClass.name}", but got "${
|
||||
e.name
|
||||
}"${msg ? `: ${msg}` : "."}`;
|
||||
|
|
|
@ -275,12 +275,12 @@ Deno.test("testingAssertFailWithWrongErrorClass", function (): void {
|
|||
(): void => {
|
||||
fail("foo");
|
||||
},
|
||||
Error,
|
||||
TypeError,
|
||||
"Failed assertion: foo"
|
||||
);
|
||||
},
|
||||
AssertionError,
|
||||
`Expected error to be instance of "Error", but was "AssertionError"`
|
||||
`Expected error to be instance of "TypeError", but was "AssertionError"`
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -626,3 +626,23 @@ Deno.test("assert diff formatting", () => {
|
|||
]`
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("Assert Throws Parent Error", () => {
|
||||
assertThrows(
|
||||
() => {
|
||||
throw new AssertionError("Fail!");
|
||||
},
|
||||
Error,
|
||||
"Fail!"
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("Assert Throws Async Parent Error", () => {
|
||||
assertThrowsAsync(
|
||||
() => {
|
||||
throw new AssertionError("Fail!");
|
||||
},
|
||||
Error,
|
||||
"Fail!"
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue