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:
Flounn
2016-09-23 22:44:01 +02:00
committed by Chuck Jazdzewski
parent 85489a166e
commit 5c4215ccb4
2 changed files with 19 additions and 3 deletions

View File

@ -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');
}));
});
});
}