feat(http): set the statusText property from the XMLHttpRequest instance

Closes #4162
This commit is contained in:
Aliaksei Palkanau 2015-09-13 19:31:56 +03:00 committed by Misko Hevery
parent 7a80f0d1e1
commit 3019140e7e
2 changed files with 37 additions and 1 deletions

View File

@ -58,7 +58,10 @@ export class XHRConnection implements Connection {
if (status === 0) {
status = body ? 200 : 0;
}
var responseOptions = new ResponseOptions({body, status, headers, url});
let statusText = _xhr.statusText || 'OK';
var responseOptions = new ResponseOptions({body, status, headers, statusText, url});
if (isPresent(baseResponseOptions)) {
responseOptions = baseResponseOptions.merge(responseOptions);
}

View File

@ -40,6 +40,8 @@ class MockBrowserXHR extends BrowserXhr {
status: number;
responseHeaders: string;
responseURL: string;
statusText: string;
constructor() {
super();
var spy = new SpyObject();
@ -51,6 +53,8 @@ class MockBrowserXHR extends BrowserXhr {
setStatusCode(status: number) { this.status = status; }
setStatusText(statusText: string) { this.statusText = statusText; }
setResponse(value: string) { this.response = value; }
setResponseText(value: string) { this.responseText = value; }
@ -354,6 +358,35 @@ export function main() {
existingXHRs[0].setStatusCode(statusCode);
existingXHRs[0].dispatchEvent('load');
}));
it('should set the status text property from the XMLHttpRequest instance if present',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var statusText = 'test';
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR());
connection.response.subscribe((res: Response) => {
expect(res.statusText).toBe(statusText);
async.done();
});
existingXHRs[0].setStatusText(statusText);
existingXHRs[0].setStatusCode(200);
existingXHRs[0].dispatchEvent('load');
}));
it('should set status text to "OK" if it is not present in XMLHttpRequest instance',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR());
connection.response.subscribe((res: Response) => {
expect(res.statusText).toBe('OK');
async.done();
});
existingXHRs[0].setStatusCode(200);
existingXHRs[0].dispatchEvent('load');
}));
});
});
}