Skip to content

Commit

Permalink
Adding tests to show config.url mutation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
multicolaure committed Sep 5, 2019
1 parent 2ee3b48 commit 958512c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/specs/requests.spec.js
Expand Up @@ -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';
Expand Down
14 changes: 14 additions & 0 deletions test/unit/adapters/http.js
Expand Up @@ -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();
});
});
});
});


0 comments on commit 958512c

Please sign in to comment.