{ "id": "api/common/http/testing/TestRequest", "title": "TestRequest", "contents": "\n\n
\n
\n
\n \n API > @angular/common > @angular/common/http/testing\n
\n \n
\n \n
\n

TestRequestlink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

A mock requests that was received and is ready to be answered.

\n\n

See more...

\n
\n \n \n \n
\n\nclass TestRequest {\n constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>)\n cancelled: boolean\n request: HttpRequest<any>\n flush(body: string | number | boolean | Object | ArrayBuffer | Blob | (string | number | boolean | Object)[], opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void\n error(error: ErrorEvent, opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void\n event(event: HttpEvent<any>): void\n}\n\n\n \n \n\n
\n\n\n \n\n \n \n
\n

Descriptionlink

\n

This interface allows access to the underlying HttpRequest, and allows\nresponding with HttpEvents or HttpErrorResponses.

\n\n \n
\n\n \n\n\n\n\n\n\n

Constructorlink

\n\n\n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n \n\n constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>)\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n request\n HttpRequest\n \n \n
\n \n observer\n Observer>\n \n \n
\n\n \n\n\n \n\n \n
\n
\n\n\n\n\n
\n

Propertieslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PropertyDescription
\n \n cancelled: boolean\n Read-Only\n \n

Whether the request was cancelled after it was sent.

\n\n \n
\n \n request: HttpRequest<any>\n \n Declared in Constructor\n \n \n
\n
\n\n\n\n
\n

Methodslink

\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n flush()\n \n link

\n \n
\n
\n

Resolve the request by returning a body plus additional HTTP information (such as response\nheaders) if provided.\nIf the request specifies an expected body type, the body is converted into the requested type.\nOtherwise, the body is converted to JSON by default.

\n\n
\n
\n \n\n flush(body: string | number | boolean | Object | ArrayBuffer | Blob | (string | number | boolean | Object)[], opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n body\n string | number | boolean | Object | ArrayBuffer | Blob | (string | number | boolean | Object)[]\n \n \n
\n \n opts\n object\n

Optional. Default is {}.

\n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

Both successful and unsuccessful responses can be delivered via flush().

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n error()\n \n link

\n \n
\n
\n

Resolve the request by returning an ErrorEvent (e.g. simulating a network failure).

\n\n
\n
\n \n\n error(error: ErrorEvent, opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n error\n ErrorEvent\n \n \n
\n \n opts\n object\n

Optional. Default is {}.

\n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n event()\n \n link

\n \n
\n
\n

Deliver an arbitrary HttpEvent (such as a progress event) on the response stream for this\nrequest.

\n\n
\n
\n \n\n event(event: HttpEvent<any>): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n event\n HttpEvent\n \n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n
\n\n\n\n \n\n\n
\n
\n\n\n" }