TestRequest

From Get docs
< @angular/common‎ | http‎ | testingAngular/docs/10/api/common/http/testing/testrequest


TestRequest

class

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

See more...

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

Description

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

Constructor

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

Parameters
request HttpRequest
observer Observer>


Properties

Property Description
cancelled: boolean

Read-Only Whether the request was cancelled after it was sent.

request: HttpRequest<any> Declared in Constructor

Methods

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 JSON by default.

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

Parameters
body number | Object | ArrayBuffer | Blob | (string | number | Object)[]
opts object Optional. Default is {}.
Returns

void


Both successful and unsuccessful responses can be delivered via flush().
Resolve the request by returning an ErrorEvent (e.g. simulating a network failure).

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

Parameters
error ErrorEvent
opts object Optional. Default is {}.
Returns

void


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

event(event: HttpEvent<any>): void

Parameters
event HttpEvent
Returns

void



© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v10.angular.io/api/common/http/testing/TestRequest