HttpTestingController

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

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

方法

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

abstract match(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean)): TestRequest[]
      
      abstract match(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean)): TestRequest[]
    
参数
match string | RequestMatch | ((req: HttpRequest) => boolean)
返回值

TestRequest[]

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

abstract expectOne(url: string, description?: string): TestRequest
      
      abstract expectOne(url: string, description?: string): TestRequest
    
参数
url string
description string

可选. 默认值是 undefined.

返回值

TestRequest


Overload #1

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

abstract expectOne(params: RequestMatch, description?: string): TestRequest
      
      abstract expectOne(params: RequestMatch, description?: string): TestRequest
    
参数
params RequestMatch
description string

可选. 默认值是 undefined.

返回值

TestRequest


Overload #2

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

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

可选. 默认值是 undefined.

返回值

TestRequest


Overload #3

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

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

可选. 默认值是 undefined.

返回值

TestRequest

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.

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

abstract expectNone(url: string, description?: string): void
      
      abstract expectNone(url: string, description?: string): void
    
参数
url string
description string

可选. 默认值是 undefined.

返回值

void


Overload #1

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

abstract expectNone(params: RequestMatch, description?: string): void
      
      abstract expectNone(params: RequestMatch, description?: string): void
    
参数
params RequestMatch
description string

可选. 默认值是 undefined.

返回值

void


Overload #2

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

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

可选. 默认值是 undefined.

返回值

void


Overload #3

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

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

可选. 默认值是 undefined.

返回值

void

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

Verify that no unmatched requests are outstanding.

abstract verify(opts?: { ignoreCancelled?: boolean; }): void
      
      abstract verify(opts?: { ignoreCancelled?: boolean; }): void
    
参数
opts object

可选. 默认值是 undefined.

返回值

void

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.