Validates that a function throws an HTTP error with specific status codes.

Specialized error validator for HTTP operations. Validates that the function throws an HttpError with one of the specified status codes. Useful for testing API endpoints, authentication, and authorization logic.

  // Validate 401 Unauthorized
await TestValidator.httpError("should return 401 for invalid token")(401)(
async () => await api.functional.getProtectedResource("invalid-token")
);

// Validate multiple possible error codes
await TestValidator.httpError("should return client error")(400, 404, 422)(
async () => await api.functional.updateNonexistentResource(data)
);

// Validate server errors
TestValidator.httpError("should handle server errors")(500, 502, 503)(
() => callFaultyEndpoint()
);

Error when function doesn't throw HttpError or status code doesn't match

  • Parameters

    • title: string

      Descriptive title used in error messages

    Returns (
        ...statuses: number[],
    ) => <T>(task: () => T) => T extends Promise<any> ? Promise<void> : void

    A currying function that accepts status codes, then the task function