mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
feat(std/testing): Allow non-void promises in assertThrowsAsync (#6052)
This commit is contained in:
parent
e3cc3db20f
commit
4b1638dccc
2 changed files with 19 additions and 4 deletions
|
@ -325,8 +325,8 @@ export function fail(msg?: string): void {
|
|||
* throws. An error class and a string that should be included in the
|
||||
* error message can also be asserted.
|
||||
*/
|
||||
export function assertThrows(
|
||||
fn: () => void,
|
||||
export function assertThrows<T = void>(
|
||||
fn: () => T,
|
||||
ErrorClass?: Constructor,
|
||||
msgIncludes = "",
|
||||
msg?: string
|
||||
|
@ -361,8 +361,8 @@ export function assertThrows(
|
|||
return error;
|
||||
}
|
||||
|
||||
export async function assertThrowsAsync(
|
||||
fn: () => Promise<void>,
|
||||
export async function assertThrowsAsync<T = void>(
|
||||
fn: () => Promise<T>,
|
||||
ErrorClass?: Constructor,
|
||||
msgIncludes = "",
|
||||
msg?: string
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
assertEquals,
|
||||
assertStrictEq,
|
||||
assertThrows,
|
||||
assertThrowsAsync,
|
||||
AssertionError,
|
||||
equal,
|
||||
fail,
|
||||
|
@ -245,6 +246,20 @@ test("testingAssertFailWithWrongErrorClass", function (): void {
|
|||
);
|
||||
});
|
||||
|
||||
test("testingAssertThrowsWithReturnType", () => {
|
||||
assertThrows(() => {
|
||||
throw new Error();
|
||||
return "a string";
|
||||
});
|
||||
});
|
||||
|
||||
test("testingAssertThrowsAsyncWithReturnType", () => {
|
||||
assertThrowsAsync(() => {
|
||||
throw new Error();
|
||||
return Promise.resolve("a Promise<string>");
|
||||
});
|
||||
});
|
||||
|
||||
const createHeader = (): string[] => [
|
||||
"",
|
||||
"",
|
||||
|
|
Loading…
Reference in a new issue