function assertRejects
assertRejects(fn: () => PromiseLike<unknown>,msg?: string): Promise<unknown>Deprecated
(will be removed after 1.0.0) Import from https://deno.land/std/assert/assert_rejects.ts instead.
Executes a function which returns a promise, expecting it to reject.
Examples
Example 1
Example 1
import { assertRejects } from "@std/testing/asserts"; await assertRejects(async () => Promise.reject(new Error())); // Doesn't throw await assertRejects(async () => console.log("Hello world")); // Throws
Parameters
fn: () => PromiseLike<unknown>optional
msg: stringReturn Type
Promise<unknown>assertRejects<E extends Error = Error>(fn: () => PromiseLike<unknown>,ErrorClass: new (...args: any[]) => E,msgIncludes?: string,msg?: string): Promise<E>Deprecated
(will be removed after 1.0.0) Import from https://deno.land/std/assert/assert_rejects.ts instead.
Executes a function which returns a promise, expecting it to reject. If it does not, then it throws. An error class and a string that should be included in the error message can also be asserted.
Examples
Example 1
Example 1
import { assertRejects } from "@std/testing/asserts"; await assertRejects(async () => Promise.reject(new Error()), Error); // Doesn't throw await assertRejects(async () => Promise.reject(new Error()), SyntaxError); // Throws