Documentation
    Preparing search index...
    • 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.

      Type Parameters

      • T extends boolean | (() => boolean) | (() => Promise<boolean>)

      Parameters

      • title: string

        Descriptive title used in error messages when validation fails

      • condition: T

        The condition to validate (boolean, function, or async function)

      Returns T extends () => Promise<boolean> ? Promise<void> : void

      Void or Promise based on the input type

        // 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()
      );

      Error with descriptive message when condition is not satisfied