API reference › @evolu/common › Assert › assertRejects
Call Signature
function assertRejects(
promise: PromiseLike<unknown>,
assertRejected: (reason: unknown) => void,
): Promise<void>;
Defined in: packages/common/src/Assert.ts:534
Asserts that a promise rejects with the expected value.
Expected values use assertEqual semantics. To perform several or specialized assertions, pass an assertion function that receives the rejection reason and returns nothing. Returning a predicate result fails. Use assertRejectsSame for SameValue or reference identity and assertRejectsInstanceOf for a runtime type.
Because JavaScript permits rejecting with functions, a function second
argument is always treated as an assertion function. Use assertRejectsSame
to assert that a particular function was rejected.
Example
import { assertRejects } from "@evolu/common";
const expected = new Error("Unavailable.");
await assertRejects(Promise.reject(expected), expected);
Call Signature
function assertRejects(
promise: PromiseLike<unknown>,
expected: unknown,
): Promise<void>;
Defined in: packages/common/src/Assert.ts:538
Asserts that a promise rejects with the expected value.
Expected values use assertEqual semantics. To perform several or specialized assertions, pass an assertion function that receives the rejection reason and returns nothing. Returning a predicate result fails. Use assertRejectsSame for SameValue or reference identity and assertRejectsInstanceOf for a runtime type.
Because JavaScript permits rejecting with functions, a function second
argument is always treated as an assertion function. Use assertRejectsSame
to assert that a particular function was rejected.
Example
import { assertRejects } from "@evolu/common";
const expected = new Error("Unavailable.");
await assertRejects(Promise.reject(expected), expected);