HttpClient is an evolution of the existing Angular HTTP API, which exists alongside of it in a separate package, @angular/common/http. This structure ensures that existing codebases can slowly migrate to the new API. The new API improves significantly on the ergonomics and features of the legacy API. A partial list of new features includes: * Typed, synchronous response body access, including support for JSON body types * JSON is an assumed default and no longer needs to be explicitly parsed * Interceptors allow middleware logic to be inserted into the pipeline * Immutable request/response objects * Progress events for both request upload and response download * Post-request verification & flush based testing framework
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {HttpRequest} from '@angular/common/http';
|
|
|
|
import {TestRequest} from './request';
|
|
|
|
/**
|
|
* Defines a matcher for requests based on URL, method, or both.
|
|
*
|
|
* @experimental
|
|
*/
|
|
export interface RequestMatch {
|
|
method?: string;
|
|
url?: string;
|
|
}
|
|
|
|
/**
|
|
* Controller to be injected into tests, that allows for mocking and flushing
|
|
* of requests.
|
|
*
|
|
* @experimental
|
|
*/
|
|
export abstract class HttpTestingController {
|
|
/**
|
|
* Search for requests that match the given parameter, without any expectations.
|
|
*/
|
|
abstract match(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): TestRequest[];
|
|
|
|
// Expect that exactly one request matches the given parameter.
|
|
abstract expectOne(url: string): TestRequest;
|
|
abstract expectOne(params: RequestMatch): TestRequest;
|
|
abstract expectOne(matchFn: ((req: HttpRequest<any>) => boolean)): TestRequest;
|
|
abstract expectOne(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): TestRequest;
|
|
|
|
// Assert that no requests match the given parameter.
|
|
abstract expectNone(url: string): void;
|
|
abstract expectNone(params: RequestMatch): void;
|
|
abstract expectNone(matchFn: ((req: HttpRequest<any>) => boolean)): void;
|
|
abstract expectNone(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): void;
|
|
|
|
// Validate that all requests which were issued were flushed.
|
|
abstract verify(opts?: {ignoreCancelled?: boolean}): void;
|
|
}
|