Fix(http): invalidStateError if response body without content (#11786)
Fix(http): invalidStateError if response body without content If the responseType has been specified and other than 'text', responseText throw an InvalidStateError exception See XHR doc => https://xhr.spec.whatwg.org/#the-responsetext-attribute Unit Test to prevent invalidStateError
This commit is contained in:
@ -686,6 +686,23 @@ Connection: keep-alive`;
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should not throw invalidStateError if response without body and responseType not equal to text',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const base = new BaseRequestOptions();
|
||||
const connection = new XHRConnection(
|
||||
new Request(
|
||||
base.merge(new RequestOptions({responseType: ResponseContentType.Json}))),
|
||||
new MockBrowserXHR());
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.json()).toBe(null);
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setStatusCode(204);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user