@ -39,8 +39,10 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
|
||||
return new Observable((observer: Observer<any>) => {
|
||||
const testReq = new TestRequest(req, observer);
|
||||
this.open.push(testReq);
|
||||
observer.next({ type: HttpEventType.Sent } as HttpEvent<any>);
|
||||
return () => { testReq._cancelled = true; };
|
||||
observer.next({type: HttpEventType.Sent} as HttpEvent<any>);
|
||||
return () => {
|
||||
testReq._cancelled = true;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@ -86,8 +88,8 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
|
||||
description = description || this.descriptionFromMatcher(match);
|
||||
const matches = this.match(match);
|
||||
if (matches.length > 1) {
|
||||
throw new Error(
|
||||
`Expected one matching request for criteria "${description}", found ${matches.length} requests.`);
|
||||
throw new Error(`Expected one matching request for criteria "${description}", found ${
|
||||
matches.length} requests.`);
|
||||
}
|
||||
if (matches.length === 0) {
|
||||
let message = `Expected one matching request for criteria "${description}", found none.`;
|
||||
@ -116,8 +118,8 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
|
||||
description = description || this.descriptionFromMatcher(match);
|
||||
const matches = this.match(match);
|
||||
if (matches.length > 0) {
|
||||
throw new Error(
|
||||
`Expected zero matching requests for criteria "${description}", found ${matches.length}.`);
|
||||
throw new Error(`Expected zero matching requests for criteria "${description}", found ${
|
||||
matches.length}.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,9 @@ export class TestRequest {
|
||||
/**
|
||||
* Whether the request was cancelled after it was sent.
|
||||
*/
|
||||
get cancelled(): boolean { return this._cancelled; }
|
||||
get cancelled(): boolean {
|
||||
return this._cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal set by `HttpClientTestingBackend`
|
||||
@ -39,7 +41,7 @@ export class TestRequest {
|
||||
* Both successful and unsuccessful responses can be delivered via `flush()`.
|
||||
*/
|
||||
flush(body: ArrayBuffer|Blob|string|number|Object|(string|number|Object|null)[]|null, opts: {
|
||||
headers?: HttpHeaders | {[name: string]: string | string[]},
|
||||
headers?: HttpHeaders|{[name: string]: string | string[]},
|
||||
status?: number,
|
||||
statusText?: string,
|
||||
} = {}): void {
|
||||
@ -75,7 +77,7 @@ export class TestRequest {
|
||||
* Resolve the request by returning an `ErrorEvent` (e.g. simulating a network failure).
|
||||
*/
|
||||
error(error: ErrorEvent, opts: {
|
||||
headers?: HttpHeaders | {[name: string]: string | string[]},
|
||||
headers?: HttpHeaders|{[name: string]: string | string[]},
|
||||
status?: number,
|
||||
statusText?: string,
|
||||
} = {}): void {
|
||||
@ -112,9 +114,8 @@ export class TestRequest {
|
||||
/**
|
||||
* Helper function to convert a response body to an ArrayBuffer.
|
||||
*/
|
||||
function _toArrayBufferBody(
|
||||
body: ArrayBuffer | Blob | string | number | Object |
|
||||
(string | number | Object | null)[]): ArrayBuffer {
|
||||
function _toArrayBufferBody(body: ArrayBuffer|Blob|string|number|Object|
|
||||
(string | number | Object | null)[]): ArrayBuffer {
|
||||
if (typeof ArrayBuffer === 'undefined') {
|
||||
throw new Error('ArrayBuffer responses are not supported on this platform.');
|
||||
}
|
||||
@ -127,9 +128,8 @@ function _toArrayBufferBody(
|
||||
/**
|
||||
* Helper function to convert a response body to a Blob.
|
||||
*/
|
||||
function _toBlob(
|
||||
body: ArrayBuffer | Blob | string | number | Object |
|
||||
(string | number | Object | null)[]): Blob {
|
||||
function _toBlob(body: ArrayBuffer|Blob|string|number|Object|
|
||||
(string | number | Object | null)[]): Blob {
|
||||
if (typeof Blob === 'undefined') {
|
||||
throw new Error('Blob responses are not supported on this platform.');
|
||||
}
|
||||
@ -146,7 +146,7 @@ function _toBlob(
|
||||
* Helper function to convert a response body to JSON data.
|
||||
*/
|
||||
function _toJsonBody(
|
||||
body: ArrayBuffer | Blob | string | number | Object | (string | number | Object | null)[],
|
||||
body: ArrayBuffer|Blob|string|number|Object|(string | number | Object | null)[],
|
||||
format: string = 'JSON'): Object|string|number|(Object | string | number)[] {
|
||||
if (typeof ArrayBuffer !== 'undefined' && body instanceof ArrayBuffer) {
|
||||
throw new Error(`Automatic conversion to ${format} is not supported for ArrayBuffers.`);
|
||||
@ -164,9 +164,8 @@ function _toJsonBody(
|
||||
/**
|
||||
* Helper function to convert a response body to a string.
|
||||
*/
|
||||
function _toTextBody(
|
||||
body: ArrayBuffer | Blob | string | number | Object |
|
||||
(string | number | Object | null)[]): string {
|
||||
function _toTextBody(body: ArrayBuffer|Blob|string|number|Object|
|
||||
(string | number | Object | null)[]): string {
|
||||
if (typeof body === 'string') {
|
||||
return body;
|
||||
}
|
||||
@ -183,9 +182,9 @@ function _toTextBody(
|
||||
* Convert a response body to the requested type.
|
||||
*/
|
||||
function _maybeConvertBody(
|
||||
responseType: string, body: ArrayBuffer | Blob | string | number | Object |
|
||||
(string | number | Object | null)[] | null): ArrayBuffer|Blob|string|number|Object|
|
||||
(string | number | Object | null)[]|null {
|
||||
responseType: string,
|
||||
body: ArrayBuffer|Blob|string|number|Object|(string | number | Object | null)[]|
|
||||
null): ArrayBuffer|Blob|string|number|Object|(string | number | Object | null)[]|null {
|
||||
if (body === null) {
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user