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

      Type Parameters

      • T

      Parameters

      • title: string

        Descriptive title used in error messages when no error occurs

      • task: () => T

        The function that should throw an error or reject

      Returns T extends Promise<any> ? Promise<void> : void

      Void or Promise based on the input type

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

      Error when the task function does not throw an error or reject