mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
Adding axios.isCancel method
This commit is contained in:
@@ -34,6 +34,12 @@ describe('static api', function () {
|
||||
it('should have factory method', function () {
|
||||
expect(typeof axios.create).toEqual('function');
|
||||
});
|
||||
|
||||
it('should have Cancel, CancelToken, and isCancel properties', function () {
|
||||
expect(typeof axios.Cancel).toEqual('function');
|
||||
expect(typeof axios.CancelToken).toEqual('function');
|
||||
expect(typeof axios.isCancel).toEqual('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('instance api', function () {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
var isCancel = require('../../../lib/cancel/isCancel');
|
||||
var Cancel = require('../../../lib/cancel/Cancel');
|
||||
|
||||
describe('isCancel', function() {
|
||||
it('returns true if value is a Cancel', function() {
|
||||
expect(isCancel(new Cancel())).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false if value is not a Cancel', function() {
|
||||
expect(isCancel({ foo: 'bar' })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -16,6 +16,7 @@ describe('instance', function () {
|
||||
'create',
|
||||
'Cancel',
|
||||
'CancelToken',
|
||||
'isCancel',
|
||||
'all',
|
||||
'spread',
|
||||
'default'].indexOf(prop) > -1) {
|
||||
|
||||
@@ -230,7 +230,7 @@ const source: CancelTokenSource = axios.CancelToken.source();
|
||||
axios.get('/user', {
|
||||
cancelToken: source.token
|
||||
}).catch((thrown: AxiosError | Cancel) => {
|
||||
if (thrown instanceof axios.Cancel) {
|
||||
if (axios.isCancel(thrown)) {
|
||||
const cancel: Cancel = thrown;
|
||||
console.log(cancel.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user