mirror of
https://github.com/axios/axios.git
synced 2026-04-14 03:11:58 +08:00
parent
8c1694e821
commit
0e33680f40
21
lib/axios.js
21
lib/axios.js
@ -2,7 +2,6 @@
|
||||
|
||||
var defaults = require('./defaults');
|
||||
var utils = require('./utils');
|
||||
var deprecatedMethod = require('./helpers/deprecatedMethod');
|
||||
var dispatchRequest = require('./core/dispatchRequest');
|
||||
var InterceptorManager = require('./core/InterceptorManager');
|
||||
|
||||
@ -43,26 +42,6 @@ var axios = module.exports = function axios(config) {
|
||||
promise = promise.then(chain.shift(), chain.shift());
|
||||
}
|
||||
|
||||
// Provide alias for success
|
||||
promise.success = function success(fn) {
|
||||
deprecatedMethod('success', 'then', 'https://github.com/mzabriskie/axios/blob/master/README.md#response-api');
|
||||
|
||||
promise.then(function(response) {
|
||||
fn(response.data, response.status, response.headers, response.config);
|
||||
});
|
||||
return promise;
|
||||
};
|
||||
|
||||
// Provide alias for error
|
||||
promise.error = function error(fn) {
|
||||
deprecatedMethod('error', 'catch', 'https://github.com/mzabriskie/axios/blob/master/README.md#response-api');
|
||||
|
||||
promise.then(null, function(response) {
|
||||
fn(response.data, response.status, response.headers, response.config);
|
||||
});
|
||||
return promise;
|
||||
};
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
|
||||
@ -15,8 +15,6 @@ describe('api', function () {
|
||||
|
||||
expect(typeof promise.then).toEqual('function');
|
||||
expect(typeof promise.catch).toEqual('function');
|
||||
expect(typeof promise.success).toEqual('function');
|
||||
expect(typeof promise.error).toEqual('function');
|
||||
});
|
||||
|
||||
it('should have defaults', function () {
|
||||
|
||||
@ -37,37 +37,6 @@ describe('promise', function () {
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should provide verbose arguments to success', function (done) {
|
||||
var request, data, status, headers, config;
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).success(function (d, s, h, c) {
|
||||
data = d;
|
||||
status = s;
|
||||
headers = h;
|
||||
config = c;
|
||||
fulfilled = true;
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: '{"hello":"world"}'
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
expect(data.hello).toEqual('world');
|
||||
expect(status).toBe(200);
|
||||
expect(headers['content-type']).toEqual('application/json');
|
||||
expect(config.url).toEqual('/foo');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should support all', function (done) {
|
||||
var fulfilled = false;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user