Descriptive title used in error messages when validation fails
The condition to validate (boolean, function, or async function)
Void or Promise
// Synchronous boolean
TestValidator.predicate("user should exist", user !== null);
// Synchronous function
TestValidator.predicate(
"array should be empty",
() => arr.length === 0,
);
// Asynchronous function
await TestValidator.predicate(
"database should be connected",
async () => await db.ping(),
);
contracts/common.md#principled-implementation A boolean, a function returning a boolean, or a function returning a promise of a boolean is evaluated, and only the exact value true passes; a false result throws the same Error in all three forms, and the asynchronous form rejects with it.
contracts/common.md#clear-and-simple-design One function whose three branches differ only in when the value is available.
Validates that a given condition evaluates to true.
Supports synchronous boolean values, synchronous functions returning boolean, and asynchronous functions returning Promise. The return
type is automatically inferred based on the input type.
Processing cost: The condition is evaluated once and asynchronous settlement adds constant bookkeeping without polling or repeating the condition.
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.