[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/common/http/testing/HttpTestingController [Back]  [Original]

HttpTestingController Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/common/http/testing

HttpTestingController

Class
stable

Controller to be injected into tests, that allows for mocking and flushing of requests.

On this page

    arrow_upward_alt Back to the top

    API

        
          abstract class HttpTestingController {  abstract match(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean)): TestRequest[];
    abstract expectOne(url: string, description?: string | undefined): TestRequest; abstract expectOne(params: RequestMatch, description?: string | undefined): TestRequest; abstract expectOne(matchFn: (req: HttpRequest<any>) => boolean, description?: string | undefined): TestRequest; abstract expectOne(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean), description?: string | undefined): TestRequest;
    abstract expectNone(url: string, description?: string | undefined): void; abstract expectNone(params: RequestMatch, description?: string | undefined): void; abstract expectNone(matchFn: (req: HttpRequest<any>) => boolean, description?: string | undefined): void; abstract expectNone(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean), description?: string | undefined): void;
    abstract verify(opts?: { ignoreCancelled?: boolean | undefined; } | undefined): void;}

    match

    TestRequest[]

    Search for requests that match the given parameter, without any expectations.

    @parammatchstring | RequestMatch | ((req: HttpRequest<any>) => boolean)
    @returnsTestRequest[]

    expectOne

    4 overloads

    Expect that a single request has been made which matches the given URL, and return its mock.

    If no such request has been made, or more than one such request has been made, fail with an error message including the given request description, if any.

    @paramurlstring
    @paramdescriptionstring | undefined
    @returnsTestRequest

    Expect that a single request has been made which matches the given parameters, and return its mock.

    If no such request has been made, or more than one such request has been made, fail with an error message including the given request description, if any.

    @paramparamsRequestMatch
    @paramdescriptionstring | undefined
    @returnsTestRequest

    Expect that a single request has been made which matches the given predicate function, and return its mock.

    If no such request has been made, or more than one such request has been made, fail with an error message including the given request description, if any.

    @parammatchFn(req: HttpRequest<any>) => boolean
    @paramdescriptionstring | undefined
    @returnsTestRequest

    Expect that a single request has been made which matches the given condition, and return its mock.

    If no such request has been made, or more than one such request has been made, fail with an error message including the given request description, if any.

    @parammatchstring | RequestMatch | ((req: HttpRequest<any>) => boolean)
    @paramdescriptionstring | undefined
    @returnsTestRequest

    expectNone

    4 overloads

    Expect that no requests have been made which match the given URL.

    If a matching request has been made, fail with an error message including the given request description, if any.

    @paramurlstring
    @paramdescriptionstring | undefined
    @returnsvoid

    Expect that no requests have been made which match the given parameters.

    If a matching request has been made, fail with an error message including the given request description, if any.

    @paramparamsRequestMatch
    @paramdescriptionstring | undefined
    @returnsvoid

    Expect that no requests have been made which match the given predicate function.

    If a matching request has been made, fail with an error message including the given request description, if any.

    @parammatchFn(req: HttpRequest<any>) => boolean
    @paramdescriptionstring | undefined
    @returnsvoid

    Expect that no requests have been made which match the given condition.

    If a matching request has been made, fail with an error message including the given request description, if any.

    @parammatchstring | RequestMatch | ((req: HttpRequest<any>) => boolean)
    @paramdescriptionstring | undefined
    @returnsvoid

    verify

    void

    Verify that no unmatched requests are outstanding.

    If any requests are outstanding, fail with an error message indicating which requests were not handled.

    If ignoreCancelled is not set (the default), verify() will also fail if cancelled requests were not explicitly matched.

    @paramopts{ ignoreCancelled?: boolean | undefined; } | undefined
    @returnsvoid
    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page