mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Refactored AxiosError to a constructor;
Refactored `Cancel` to a constructor, a subclass of the `AxiosError`; Expose CanceledError class; Refactored axios error codes; Added `toFlatObject` util;
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
var Cancel = require('../../../lib/cancel/Cancel');
|
||||
|
||||
describe('Cancel', function() {
|
||||
describe('toString', function() {
|
||||
it('returns correct result when message is not specified', function() {
|
||||
var cancel = new Cancel();
|
||||
expect(cancel.toString()).toBe('Cancel');
|
||||
});
|
||||
|
||||
it('returns correct result when message is specified', function() {
|
||||
var cancel = new Cancel('Operation has been canceled.');
|
||||
expect(cancel.toString()).toBe('Cancel: Operation has been canceled.');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
var CancelToken = require('../../../lib/cancel/CancelToken');
|
||||
var Cancel = require('../../../lib/cancel/Cancel');
|
||||
var CanceledError = require('../../../lib/cancel/CanceledError');
|
||||
|
||||
describe('CancelToken', function() {
|
||||
describe('constructor', function() {
|
||||
@@ -17,13 +17,13 @@ describe('CancelToken', function() {
|
||||
});
|
||||
|
||||
describe('reason', function() {
|
||||
it('returns a Cancel if cancellation has been requested', function() {
|
||||
it('returns a CanceledError if cancellation has been requested', function() {
|
||||
var cancel;
|
||||
var token = new CancelToken(function(c) {
|
||||
cancel = c;
|
||||
});
|
||||
cancel('Operation has been canceled.');
|
||||
expect(token.reason).toEqual(jasmine.any(Cancel));
|
||||
expect(token.reason).toEqual(jasmine.any(CanceledError));
|
||||
expect(token.reason.message).toBe('Operation has been canceled.');
|
||||
});
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('CancelToken', function() {
|
||||
cancel = c;
|
||||
});
|
||||
token.promise.then(function onFulfilled(value) {
|
||||
expect(value).toEqual(jasmine.any(Cancel));
|
||||
expect(value).toEqual(jasmine.any(CanceledError));
|
||||
expect(value.message).toBe('Operation has been canceled.');
|
||||
done();
|
||||
});
|
||||
@@ -50,7 +50,7 @@ describe('CancelToken', function() {
|
||||
|
||||
describe('throwIfRequested', function() {
|
||||
it('throws if cancellation has been requested', function() {
|
||||
// Note: we cannot use expect.toThrowError here as Cancel does not inherit from Error
|
||||
// Note: we cannot use expect.toThrowError here as CanceledError does not inherit from Error
|
||||
var cancel;
|
||||
var token = new CancelToken(function(c) {
|
||||
cancel = c;
|
||||
@@ -60,8 +60,8 @@ describe('CancelToken', function() {
|
||||
token.throwIfRequested();
|
||||
fail('Expected throwIfRequested to throw.');
|
||||
} catch (thrown) {
|
||||
if (!(thrown instanceof Cancel)) {
|
||||
fail('Expected throwIfRequested to throw a Cancel, but it threw ' + thrown + '.');
|
||||
if (!(thrown instanceof CanceledError)) {
|
||||
fail('Expected throwIfRequested to throw a CanceledError, but it threw ' + thrown + '.');
|
||||
}
|
||||
expect(thrown.message).toBe('Operation has been canceled.');
|
||||
}
|
||||
@@ -80,7 +80,7 @@ describe('CancelToken', function() {
|
||||
expect(source.cancel).toEqual(jasmine.any(Function));
|
||||
expect(source.token.reason).toBeUndefined();
|
||||
source.cancel('Operation has been canceled.');
|
||||
expect(source.token.reason).toEqual(jasmine.any(Cancel));
|
||||
expect(source.token.reason).toEqual(jasmine.any(CanceledError));
|
||||
expect(source.token.reason.message).toBe('Operation has been canceled.');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
var CanceledError = require('../../../lib/cancel/CanceledError');
|
||||
|
||||
describe('Cancel', function() {
|
||||
describe('toString', function() {
|
||||
it('returns correct result when message is not specified', function() {
|
||||
var cancel = new CanceledError();
|
||||
expect(cancel.toString()).toBe('CanceledError: canceled');
|
||||
});
|
||||
|
||||
it('returns correct result when message is specified', function() {
|
||||
var cancel = new CanceledError('Operation has been canceled.');
|
||||
expect(cancel.toString()).toBe('CanceledError: Operation has been canceled.');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,12 +1,12 @@
|
||||
var isCancel = require('../../../lib/cancel/isCancel');
|
||||
var Cancel = require('../../../lib/cancel/Cancel');
|
||||
var CanceledError = require('../../../lib/cancel/CanceledError');
|
||||
|
||||
describe('isCancel', function() {
|
||||
it('returns true if value is a Cancel', function() {
|
||||
expect(isCancel(new Cancel())).toBe(true);
|
||||
it('returns true if value is a CanceledError', function() {
|
||||
expect(isCancel(new CanceledError())).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false if value is not a Cancel', function() {
|
||||
it('returns false if value is not a CanceledError', function() {
|
||||
expect(isCancel({ foo: 'bar' })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user