fix(common): add boolean to valid json for testing (#37893)
boolean is a valid json but at present we cannot test Http request using boolean added support for boolean requests Fixes #20690 PR Close #37893
This commit is contained in:
parent
ee03408c44
commit
3c474ecf56
|
@ -33,7 +33,7 @@ export declare class TestRequest {
|
|||
statusText?: string;
|
||||
}): void;
|
||||
event(event: HttpEvent<any>): void;
|
||||
flush(body: ArrayBuffer | Blob | string | number | Object | (string | number | Object | null)[] | null, opts?: {
|
||||
flush(body: ArrayBuffer | Blob | boolean | string | number | Object | (boolean | string | number | Object | null)[] | null, opts?: {
|
||||
headers?: HttpHeaders | {
|
||||
[name: string]: string | string[];
|
||||
};
|
||||
|
|
|
@ -31,6 +31,13 @@ import {toArray} from 'rxjs/operators';
|
|||
});
|
||||
backend.expectOne('/test').flush({'data': 'hello world'});
|
||||
});
|
||||
it('should allow flushing requests with a boolean value', (done: DoneFn) => {
|
||||
client.get('/test').subscribe(res => {
|
||||
expect((res as any)).toEqual(true);
|
||||
done();
|
||||
});
|
||||
backend.expectOne('/test').flush(true);
|
||||
});
|
||||
it('for text data', done => {
|
||||
client.get('/test', {responseType: 'text'}).subscribe(res => {
|
||||
expect(res).toEqual('hello world');
|
||||
|
|
|
@ -40,11 +40,14 @@ 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[]},
|
||||
status?: number,
|
||||
statusText?: string,
|
||||
} = {}): void {
|
||||
flush(
|
||||
body: ArrayBuffer|Blob|boolean|string|number|Object|(boolean|string|number|Object|null)[]|
|
||||
null,
|
||||
opts: {
|
||||
headers?: HttpHeaders|{[name: string]: string | string[]},
|
||||
status?: number,
|
||||
statusText?: string,
|
||||
} = {}): void {
|
||||
if (this.cancelled) {
|
||||
throw new Error(`Cannot flush a cancelled request.`);
|
||||
}
|
||||
|
@ -146,7 +149,8 @@ function _toBlob(body: ArrayBuffer|Blob|string|number|Object|
|
|||
* 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|boolean|string|number|Object|
|
||||
(boolean | 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.`);
|
||||
|
@ -155,7 +159,7 @@ function _toJsonBody(
|
|||
throw new Error(`Automatic conversion to ${format} is not supported for Blobs.`);
|
||||
}
|
||||
if (typeof body === 'string' || typeof body === 'number' || typeof body === 'object' ||
|
||||
Array.isArray(body)) {
|
||||
typeof body === 'boolean' || Array.isArray(body)) {
|
||||
return body;
|
||||
}
|
||||
throw new Error(`Automatic conversion to ${format} is not supported for response type.`);
|
||||
|
|
Loading…
Reference in New Issue