From 8c65427730b6c6074a2f7c060aea8cd7473a34f8 Mon Sep 17 00:00:00 2001 From: Stefan Dobrev Date: Fri, 14 Aug 2015 20:05:10 +0300 Subject: [PATCH] Fix XHR statusText property to return just the text In order to follow the spec the XHR statusText property should return just the status text without the status code. Adding tests to guard this behavior. --- apps/tests/xhr-tests.ts | 18 ++++++++++++++++++ xhr/xhr.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/tests/xhr-tests.ts b/apps/tests/xhr-tests.ts index a71f5566f..811ae4769 100644 --- a/apps/tests/xhr-tests.ts +++ b/apps/tests/xhr-tests.ts @@ -221,6 +221,24 @@ export function test_raises_onload_Event(done) { xhr.send(); } +export function test_sets_status_and_statusText(done) { + let xhr = new XMLHttpRequest(); + xhr.onreadystatechange = () => { + if (xhr.readyState > 3) { + try { + TKUnit.assertEqual(xhr.status, 200); + TKUnit.assertEqual(xhr.statusText, 'OK'); + done(null); + } + catch (err) { + done(err); + } + } + }; + xhr.open("GET", "https://httpbin.org/get"); + xhr.send(); +} + export function test_raises_onerror_Event(done) { let xhr = new XMLHttpRequest(); xhr.onerror = () => { diff --git a/xhr/xhr.ts b/xhr/xhr.ts index b075abe6e..b9dc5b2e5 100644 --- a/xhr/xhr.ts +++ b/xhr/xhr.ts @@ -197,7 +197,7 @@ export class XMLHttpRequest { if (this._readyState === this.UNSENT || this._readyState === this.OPENED || this._errorFlag) { return ""; } - return this._status + " " + statuses[this._status]; + return statuses[this._status]; } }