mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
Allow custom HTTP status code error ranges (#308)
Adding support for custom HTTP status code error ranges
This commit is contained in:
committed by
Matt Zabriskie
parent
093593cbca
commit
fa9444e0ba
@@ -0,0 +1,75 @@
|
||||
var settle = require('../../../lib/helpers/settle');
|
||||
|
||||
describe('helpers::settle', function() {
|
||||
var resolve;
|
||||
var reject;
|
||||
|
||||
beforeEach(function() {
|
||||
resolve = jasmine.createSpy('resolve');
|
||||
reject = jasmine.createSpy('reject');
|
||||
});
|
||||
|
||||
it('should resolve promise if status is not set', function() {
|
||||
var response = {
|
||||
config: {
|
||||
validateStatus: function() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
settle(resolve, reject, response);
|
||||
expect(resolve).toHaveBeenCalledWith(response);
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should resolve promise if validateStatus is not set', function() {
|
||||
var response = {
|
||||
status: 500,
|
||||
config: {
|
||||
}
|
||||
};
|
||||
settle(resolve, reject, response);
|
||||
expect(resolve).toHaveBeenCalledWith(response);
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should resolve promise if validateStatus returns true', function() {
|
||||
var response = {
|
||||
status: 500,
|
||||
config: {
|
||||
validateStatus: function() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
settle(resolve, reject, response);
|
||||
expect(resolve).toHaveBeenCalledWith(response);
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reject promise if validateStatus returns false', function() {
|
||||
var response = {
|
||||
status: 500,
|
||||
config: {
|
||||
validateStatus: function() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
settle(resolve, reject, response);
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(reject).toHaveBeenCalledWith(response);
|
||||
});
|
||||
|
||||
it('should pass status to validateStatus', function() {
|
||||
var validateStatus = jasmine.createSpy('validateStatus');
|
||||
var response = {
|
||||
status: 500,
|
||||
config: {
|
||||
validateStatus: validateStatus
|
||||
}
|
||||
};
|
||||
settle(resolve, reject, response);
|
||||
expect(validateStatus).toHaveBeenCalledWith(500);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user