HttpTestingController

class

npm Package @angular/common
Module import { HttpTestingController } from '@angular/common/http/testing';
Source common/http/testing/src/api.ts

Overview

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

Description

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

Members

match(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean)): TestRequest[]

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

expectOne(url: string, description?: string): TestRequest

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.

Overloads

expectOne(params: RequestMatch, description?: string): TestRequest

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.

expectOne(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): TestRequest

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.

expectOne(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean), description?: string): TestRequest

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.

expectNone(url: string, description?: string): void

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.

Overloads

expectNone(params: RequestMatch, description?: string): void

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.

expectNone(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): void

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.

expectNone(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean), description?: string): void

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.

verify(opts?: { ignoreCancelled?: boolean; }): 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.

© 2010–2018 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v5.angular.io/api/common/http/testing/HttpTestingController