class
final
A mock requests that was received and is ready to be answered.
class TestRequest { constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>) cancelled: boolean request: HttpRequest<any> flush(body: string | number | boolean | Object | ArrayBuffer | Blob | (string | number | boolean | Object)[], opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void error(error: ErrorEvent | ProgressEvent<EventTarget>, opts: TestRequestErrorOptions = {}): void event(event: HttpEvent<any>): void }
This interface allows access to the underlying HttpRequest
, and allows responding with HttpEvent
s or HttpErrorResponse
s.
|
request | HttpRequest<any> | |
observer | Observer<HttpEvent<any>> |
Property | Description |
---|---|
cancelled: boolean | Read-Only Whether the request was cancelled after it was sent. |
request: HttpRequest<any> | Declared in Constructor |
flush() | ||||||
---|---|---|---|---|---|---|
Resolve the request by returning a body plus additional HTTP information (such as response headers) if provided. If the request specifies an expected body type, the body is converted into the requested type. Otherwise, the body is converted to | ||||||
|
body | string | number | boolean | Object | ArrayBuffer | Blob | (string | number | boolean | Object)[] | |
opts | object | Optional. Default is |
void
Both successful and unsuccessful responses can be delivered via flush()
.
error() | ||||||
---|---|---|---|---|---|---|
Resolve the request by returning an |
error | ErrorEvent | |
opts | TestRequestErrorOptions | Optional. Default is |
void
Resolve the request by returning an ProgressEvent
(e.g. simulating a network failure).
error(error: ProgressEvent<EventTarget>, opts?: TestRequestErrorOptions): void
error | ProgressEvent<EventTarget> | |
opts | TestRequestErrorOptions | Optional. Default is |
void
event() |
---|
Deliver an arbitrary |
© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/common/http/testing/TestRequest