mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
Fixing #385 - Keep defaults local to instance
This commit is contained in:
@@ -148,14 +148,14 @@ describe('defaults', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be used by custom instance if set after instance created', function (done) {
|
||||
it('should not be used by custom instance if set after instance created', function (done) {
|
||||
var instance = axios.create();
|
||||
axios.defaults.baseURL = 'http://example.org/';
|
||||
|
||||
instance.get('/foo');
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
expect(request.url).toBe('http://example.org/foo');
|
||||
expect(request.url).toBe('/foo');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -81,4 +81,32 @@ describe('options', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should change only the baseURL of the specified instance', function() {
|
||||
var instance1 = axios.create();
|
||||
var instance2 = axios.create();
|
||||
|
||||
instance1.defaults.baseURL = 'http://instance1.example.com/';
|
||||
|
||||
expect(instance2.defaults.baseURL).not.toBe('http://instance1.example.com/');
|
||||
});
|
||||
|
||||
it('should change only the headers of the specified instance', function() {
|
||||
var instance1 = axios.create();
|
||||
var instance2 = axios.create();
|
||||
|
||||
instance1.defaults.headers.common.Authorization = 'faketoken';
|
||||
instance2.defaults.headers.common.Authorization = 'differentfaketoken';
|
||||
|
||||
instance1.defaults.headers.common['Content-Type'] = 'application/xml';
|
||||
instance2.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
expect(axios.defaults.headers.common.Authorization).toBe(undefined);
|
||||
expect(instance1.defaults.headers.common.Authorization).toBe('faketoken');
|
||||
expect(instance2.defaults.headers.common.Authorization).toBe('differentfaketoken');
|
||||
|
||||
expect(axios.defaults.headers.common['Content-Type']).toBe(undefined);
|
||||
expect(instance1.defaults.headers.common['Content-Type']).toBe('application/xml');
|
||||
expect(instance2.defaults.headers.common['Content-Type']).toBe('application/x-www-form-urlencoded');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user