From 46eee269da70c33420ff3f8490836674f2a44ceb Mon Sep 17 00:00:00 2001 From: Matt Zabriskie Date: Thu, 23 Jun 2016 15:19:10 -0600 Subject: [PATCH] Fixing custom instance defaults closes #341 --- lib/axios.js | 3 +-- lib/core/Axios.js | 2 +- test/specs/instance.spec.js | 9 +++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/axios.js b/lib/axios.js index 3f8b416..67f9d6f 100644 --- a/lib/axios.js +++ b/lib/axios.js @@ -1,11 +1,10 @@ 'use strict'; -var defaults = require('./defaults'); var utils = require('./utils'); var bind = require('./helpers/bind'); var Axios = require('./core/Axios'); -var defaultInstance = new Axios(defaults); +var defaultInstance = new Axios(); var axios = module.exports = bind(Axios.prototype.request, defaultInstance); // Copy Axios.prototype to axios instance diff --git a/lib/core/Axios.js b/lib/core/Axios.js index 69dcfae..5ace5cb 100644 --- a/lib/core/Axios.js +++ b/lib/core/Axios.js @@ -13,7 +13,7 @@ var combineURLs = require('./../helpers/combineURLs'); * @param {Object} defaultConfig The default config for the instance */ function Axios(defaultConfig) { - this.defaults = utils.merge({}, defaultConfig); + this.defaults = utils.merge(defaults, defaultConfig); this.interceptors = { request: new InterceptorManager(), response: new InterceptorManager() diff --git a/test/specs/instance.spec.js b/test/specs/instance.spec.js index 3885183..19f1331 100644 --- a/test/specs/instance.spec.js +++ b/test/specs/instance.spec.js @@ -29,6 +29,15 @@ describe('instance', function () { }); }); + it('should have defaults.headers', function () { + var instance = axios.create({ + baseURL: 'https://api.example.com' + }); + + expect(typeof instance.defaults.headers, 'object'); + expect(typeof instance.defaults.headers.common, 'object'); + }); + it('should have interceptors on the instance', function (done) { axios.interceptors.request.use(function (config) { config.foo = true;