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

      Type Parameters

      • T

      Parameters

      • title: string

        Descriptive title used in error messages

      • status: number | number[]

        Expected status code(s), can be a single number or array

      • task: () => T

        The function that should throw an HttpError

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

      Void or Promise based on the input type

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