Descriptive title used in error messages when no error occurs
The function that should throw an error or reject
Void or Promise
// Synchronous error validation
TestValidator.error("should reject invalid email", () =>
validateEmail("invalid-email"),
);
// Asynchronous error validation
await TestValidator.error(
"should reject unauthorized access",
async () => await api.functional.getSecretData(),
);
// Validate input validation
TestValidator.error("should throw on empty string", () =>
processRequiredInput(""),
);
contracts/common.md#principled-implementation The task is run inside a try so that only its own throw counts, a promise is awaited and a rejection counts as the expected error, and a task that neither throws nor rejects raises the failure outside the try, so the failure cannot be swallowed.
contracts/common.md#clear-and-simple-design One function with a synchronous and an asynchronous path selected by the returned value.
Validates that a function throws an error or rejects when executed.
Expects the provided function to fail. If the function executes successfully without throwing an error or rejecting, this validator will throw an exception. Supports both synchronous and asynchronous functions.
Processing cost: The task is invoked once and its settlement is classified with constant bookkeeping; no retry or repeated execution occurs.
Reuse: Each invocation must evaluate its supplied task or request to observe current behavior; prior results cannot replace these effectful checks.
Resource ownership: The returned promise retains invocation-local state until settlement. The callback owns its external resources, and this validator provides no cancellation or timeout.