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.

  // 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

  • Parameters

    • title: string

      Descriptive title used in error messages when no error occurs

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

    A currying function that accepts the task function to validate