From 69af75623c864ed477230d1c9978e71e2467844f Mon Sep 17 00:00:00 2001 From: mzabriskie Date: Fri, 13 Mar 2015 17:07:52 -0600 Subject: [PATCH] Adding statusText to response closes #46 --- lib/adapters/http.js | 1 + lib/adapters/xhr.js | 1 + test/specs/wrapper.spec.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 81da7ac..1fb5b2b 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -65,6 +65,7 @@ module.exports = function httpAdapter(resolve, reject, config) { config.transformResponse ), status: res.statusCode, + statusText: res.statusMessage, headers: res.headers, config: config }; diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index 3ff6861..2e4106f 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -42,6 +42,7 @@ module.exports = function xhrAdapter(resolve, reject, config) { config.transformResponse ), status: request.status, + statusText: request.statusText, headers: headers, config: config }; diff --git a/test/specs/wrapper.spec.js b/test/specs/wrapper.spec.js index b81a91a..f1cde3a 100644 --- a/test/specs/wrapper.spec.js +++ b/test/specs/wrapper.spec.js @@ -146,6 +146,38 @@ describe('wrapper', function () { }, 0); }); + it('should supply correct response', function (done) { + var request, response; + + axios({ + method: 'post', + url: '/foo' + }).then(function (res) { + response = res; + }); + + setTimeout(function () { + request = jasmine.Ajax.requests.mostRecent(); + + request.respondWith({ + status: 200, + statusText: 'OK', + responseText: '{"foo": "bar"}', + headers: { + 'Content-Type': 'application/json' + } + }); + + setTimeout(function () { + expect(response.data.foo).toEqual('bar'); + expect(response.status).toEqual(200); + expect(response.statusText).toEqual('OK'); + expect(response.headers['content-type']).toEqual('application/json'); + done(); + }, 0); + }, 0); + }); + it('should support array buffer response', function (done) { var request, response;