TestRequest
class
npm Package | @angular/common |
---|---|
Module | import { TestRequest } from '@angular/common/http/testing'; |
Source | common/http/testing/src/request.ts |
Overview
class TestRequest { constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>) get cancelled: boolean request: HttpRequest<any> flush(body: ArrayBuffer|Blob|string|number|Object|(string|number|Object|null)[]|null, opts: {...}): void error(error: ErrorEvent, opts: {...}): void event(event: HttpEvent<any>): void }
Description
A mock requests that was received and is ready to be answered.
This interface allows access to the underlying HttpRequest
, and allows responding with HttpEvent
s or HttpErrorResponse
s.
Constructor
constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>)
Members
get cancelled: boolean
Whether the request was cancelled after it was sent.
request: HttpRequest<any>
flush(body: ArrayBuffer|Blob|string|number|Object|(string|number|Object|null)[]|null, opts: {
headers?: HttpHeaders | {[name: string]: string | string[]},
status?: number,
statusText?: string,
} = {}): void
Resolve the request by returning a body plus additional HTTP information (such as response headers) if provided.
Both successful and unsuccessful responses can be delivered via flush()
.
error(error: ErrorEvent, opts: {
headers?: HttpHeaders | {[name: string]: string | string[]},
status?: number,
statusText?: string,
} = {}): void
Resolve the request by returning an ErrorEvent
(e.g. simulating a network failure).
event(event: HttpEvent<any>): void
Deliver an arbitrary HttpEvent
(such as a progress event) on the response stream for this request.
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v4.angular.io/api/common/http/testing/TestRequest