From 958512cc9c2ae577455516d1d5291c76b39fd7ac Mon Sep 17 00:00:00 2001 From: multicolaure Date: Thu, 5 Sep 2019 11:03:30 +0200 Subject: [PATCH] Adding tests to show config.url mutation Because config.url is modified while processing the request when the baseURL is set, it is impossible to perform a retry with the provided config object. Ref #1628 --- test/specs/requests.spec.js | 24 ++++++++++++++++++++++++ test/unit/adapters/http.js | 14 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/test/specs/requests.spec.js b/test/specs/requests.spec.js index 78df9f1d9c..e73eedc810 100644 --- a/test/specs/requests.spec.js +++ b/test/specs/requests.spec.js @@ -245,6 +245,30 @@ describe('requests', function () { }); }); + it('should not modify the config url with relative baseURL', function (done) { + var config; + + axios.get('/foo', { + baseURL: '/api' + }).catch(function (error) { + config = error.config; + }); + + getAjaxRequest().then(function (request) { + request.respondWith({ + status: 404, + statusText: 'NOT FOUND', + responseText: 'Resource not found' + }); + + setTimeout(function () { + expect(config.baseURL).toEqual('/api'); + expect(config.url).toEqual('/foo'); + done(); + }, 100); + }); + }); + it('should allow overriding Content-Type header case-insensitive', function (done) { var response; var contentType = 'application/vnd.myapp.type+json'; diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index f35c0e0707..6e9c57f94a 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -646,6 +646,20 @@ describe('supports http with nodejs', function () { }); }); }); + + it('should combine baseURL and url', function (done) { + server = http.createServer(function (req, res) { + res.end(); + }).listen(4444, function () { + axios.get('/foo', { + baseURL: 'http://localhost:4444/', + }).then(function (res) { + assert.equal(res.config.baseURL, 'http://localhost:4444/'); + assert.equal(res.config.url, '/foo'); + done(); + }); + }); + }); });