Skip to content

Commit

Permalink
Fixing axios#433 - instance should inherit defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
yanivefraim committed Nov 8, 2016
1 parent 949d08d commit 194f41a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/axios.js
Expand Up @@ -31,7 +31,7 @@ axios.Axios = Axios;

// Factory for creating new instances
axios.create = function create(defaultConfig) {
return createInstance(defaultConfig);
return createInstance(utils.merge(axios.defaults, defaultConfig));
};

// Expose Cancel & CancelToken
Expand Down
13 changes: 13 additions & 0 deletions test/specs/instance.spec.js
Expand Up @@ -68,6 +68,19 @@ describe('instance', function () {
expect(typeof instance.defaults.headers.common, 'object');
});

it('should inherit defaults options', function (done) {
var oldBaseURL = axios.defaults.baseURL;
axios.defaults.baseURL = 'http://example.com/';
var instance = axios.create();
instance.get('/foo');

getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://example.com/foo');
axios.defaults.baseURL = oldBaseURL;
done();
});
});

it('should have interceptors on the instance', function (done) {
axios.interceptors.request.use(function (config) {
config.foo = true;
Expand Down

0 comments on commit 194f41a

Please sign in to comment.