mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
Mended merge conflicts
This commit is contained in:
@@ -36,7 +36,7 @@ describe('static api', function () {
|
||||
expect(typeof axios.create).toEqual('function');
|
||||
});
|
||||
|
||||
it('should have Cancel, CancelToken, and isCancel properties', function () {
|
||||
it('should have CanceledError, CancelToken, and isCancel properties', function () {
|
||||
expect(typeof axios.Cancel).toEqual('function');
|
||||
expect(typeof axios.CancelToken).toEqual('function');
|
||||
expect(typeof axios.isCancel).toEqual('function');
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('cancel', function() {
|
||||
});
|
||||
|
||||
describe('when called before sending request', function() {
|
||||
it('rejects Promise with a Cancel object', function(done) {
|
||||
it('rejects Promise with a CanceledError object', function(done) {
|
||||
var source = CancelToken.source();
|
||||
source.cancel('Operation has been canceled.');
|
||||
axios.get('/foo', {
|
||||
@@ -28,7 +28,7 @@ describe('cancel', function() {
|
||||
});
|
||||
|
||||
describe('when called after request has been sent', function() {
|
||||
it('rejects Promise with a Cancel object', function(done) {
|
||||
it('rejects Promise with a CanceledError object', function(done) {
|
||||
var source = CancelToken.source();
|
||||
axios.get('/foo/bar', {
|
||||
cancelToken: source.token
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
var AxiosError = require('../../../lib/core/AxiosError');
|
||||
|
||||
describe('core::AxiosError', function() {
|
||||
it('should create an Error with message, config, code, request, response and isAxiosError', function() {
|
||||
var request = { path: '/foo' };
|
||||
var response = { status: 200, data: { foo: 'bar' } };
|
||||
var error = new AxiosError('Boom!', 'ESOMETHING', { foo: 'bar' }, request, response);
|
||||
expect(error instanceof Error).toBe(true);
|
||||
expect(error.message).toBe('Boom!');
|
||||
expect(error.config).toEqual({ foo: 'bar' });
|
||||
expect(error.code).toBe('ESOMETHING');
|
||||
expect(error.request).toBe(request);
|
||||
expect(error.response).toBe(response);
|
||||
expect(error.isAxiosError).toBe(true);
|
||||
});
|
||||
it('should create an Error that can be serialized to JSON', function() {
|
||||
// Attempting to serialize request and response results in
|
||||
// TypeError: Converting circular structure to JSON
|
||||
var request = { path: '/foo' };
|
||||
var response = { status: 200, data: { foo: 'bar' } };
|
||||
var error = new AxiosError('Boom!', 'ESOMETHING', { foo: 'bar' }, request, response);
|
||||
var json = error.toJSON();
|
||||
expect(json.message).toBe('Boom!');
|
||||
expect(json.config).toEqual({ foo: 'bar' });
|
||||
expect(json.code).toBe('ESOMETHING');
|
||||
expect(json.status).toBe(200);
|
||||
expect(json.request).toBe(undefined);
|
||||
expect(json.response).toBe(undefined);
|
||||
});
|
||||
|
||||
describe('core::createError.from', function() {
|
||||
it('should add config, config, request and response to error', function() {
|
||||
var error = new Error('Boom!');
|
||||
var request = { path: '/foo' };
|
||||
var response = { status: 200, data: { foo: 'bar' } };
|
||||
|
||||
var axiosError = AxiosError.from(error, 'ESOMETHING', { foo: 'bar' }, request, response);
|
||||
expect(axiosError.config).toEqual({ foo: 'bar' });
|
||||
expect(axiosError.code).toBe('ESOMETHING');
|
||||
expect(axiosError.request).toBe(request);
|
||||
expect(axiosError.response).toBe(response);
|
||||
expect(axiosError.isAxiosError).toBe(true);
|
||||
});
|
||||
|
||||
it('should return error', function() {
|
||||
var error = new Error('Boom!');
|
||||
expect(AxiosError.from(error, 'ESOMETHING', { foo: 'bar' }) instanceof AxiosError).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,30 +0,0 @@
|
||||
var createError = require('../../../lib/core/createError');
|
||||
|
||||
describe('core::createError', function() {
|
||||
it('should create an Error with message, config, code, request, response and isAxiosError', function() {
|
||||
var request = { path: '/foo' };
|
||||
var response = { status: 200, data: { foo: 'bar' } };
|
||||
var error = createError('Boom!', { foo: 'bar' }, 'ESOMETHING', request, response);
|
||||
expect(error instanceof Error).toBe(true);
|
||||
expect(error.message).toBe('Boom!');
|
||||
expect(error.config).toEqual({ foo: 'bar' });
|
||||
expect(error.code).toBe('ESOMETHING');
|
||||
expect(error.request).toBe(request);
|
||||
expect(error.response).toBe(response);
|
||||
expect(error.isAxiosError).toBe(true);
|
||||
});
|
||||
it('should create an Error that can be serialized to JSON', function() {
|
||||
// Attempting to serialize request and response results in
|
||||
// TypeError: Converting circular structure to JSON
|
||||
var request = { path: '/foo' };
|
||||
var response = { status: 200, data: { foo: 'bar' } };
|
||||
var error = createError('Boom!', { foo: 'bar' }, 'ESOMETHING', request, response);
|
||||
var json = error.toJSON();
|
||||
expect(json.message).toBe('Boom!');
|
||||
expect(json.config).toEqual({ foo: 'bar' });
|
||||
expect(json.code).toBe('ESOMETHING');
|
||||
expect(json.status).toBe(200);
|
||||
expect(json.request).toBe(undefined);
|
||||
expect(json.response).toBe(undefined);
|
||||
});
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
var enhanceError = require('../../../lib/core/enhanceError');
|
||||
|
||||
describe('core::enhanceError', function() {
|
||||
it('should add config, code, request, response, and toJSON function to error', function() {
|
||||
var error = new Error('Boom!');
|
||||
var request = { path: '/foo' };
|
||||
var response = { status: 200, data: { foo: 'bar' } };
|
||||
|
||||
enhanceError(error, { foo: 'bar' }, 'ESOMETHING', request, response);
|
||||
expect(error.config).toEqual({ foo: 'bar' });
|
||||
expect(error.code).toBe('ESOMETHING');
|
||||
expect(error.request).toBe(request);
|
||||
expect(error.response).toBe(response);
|
||||
expect(typeof error.toJSON).toBe('function');
|
||||
expect(error.isAxiosError).toBe(true);
|
||||
});
|
||||
|
||||
it('should serialize to JSON with a status of null when there is no response', function() {
|
||||
var error = new Error('Boom!');
|
||||
var request = { path: '/foo' };
|
||||
var response = undefined;
|
||||
|
||||
var errorAsJson = enhanceError(error, { foo: 'bar' }, 'ESOMETHING', request, response).toJSON();
|
||||
expect(errorAsJson.status).toEqual(null);
|
||||
});
|
||||
|
||||
it('should return error', function() {
|
||||
var error = new Error('Boom!');
|
||||
expect(enhanceError(error, { foo: 'bar' }, 'ESOMETHING')).toBe(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
var createError = require('../../../lib/core/createError');
|
||||
var enhanceError = require('../../../lib/core/enhanceError');
|
||||
var AxiosError = require('../../../lib/core/AxiosError');
|
||||
var isAxiosError = require('../../../lib/helpers/isAxiosError');
|
||||
|
||||
describe('helpers::isAxiosError', function () {
|
||||
it('should return true if the error is created by core::createError', function () {
|
||||
expect(isAxiosError(createError('Boom!', { foo: 'bar' })))
|
||||
describe('helpers::isAxiosError', function() {
|
||||
it('should return true if the error is created by core::createError', function() {
|
||||
expect(isAxiosError(new AxiosError('Boom!', null, { foo: 'bar' })))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if the error is enhanced by core::enhanceError', function () {
|
||||
expect(isAxiosError(enhanceError(new Error('Boom!'), { foo: 'bar' })))
|
||||
it('should return true if the error is enhanced by core::enhanceError', function() {
|
||||
expect(isAxiosError(AxiosError.from(new Error('Boom!'), null, { foo: 'bar' })))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if the error is a normal Error instance', function () {
|
||||
it('should return false if the error is a normal Error instance', function() {
|
||||
expect(isAxiosError(new Error('Boom!')))
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
@@ -13,8 +13,10 @@ describe('instance', function () {
|
||||
for (var prop in axios) {
|
||||
if ([
|
||||
'Axios',
|
||||
'AxiosError',
|
||||
'create',
|
||||
'Cancel',
|
||||
'CanceledError',
|
||||
'CancelToken',
|
||||
'isCancel',
|
||||
'all',
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
var AxiosError = require("../../lib/core/AxiosError");
|
||||
|
||||
describe('transform', function () {
|
||||
beforeEach(function () {
|
||||
jasmine.Ajax.install();
|
||||
@@ -64,6 +66,7 @@ describe('transform', function () {
|
||||
setTimeout(function () {
|
||||
expect(thrown).toBeTruthy();
|
||||
expect(thrown.name).toContain('SyntaxError');
|
||||
expect(thrown.code).toEqual(AxiosError.ERR_BAD_RESPONSE);
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
var toFlatObject = require('../../../lib/utils').toFlatObject;
|
||||
|
||||
describe('utils::toFlatObject', function () {
|
||||
it('should resolve object proto chain to a flat object representation', function () {
|
||||
var a = {x: 1};
|
||||
var b = Object.create(a, {y: {value: 2}});
|
||||
var c = Object.create(b, {z: {value: 3}});
|
||||
expect(toFlatObject(c)).toEqual({x: 1, y: 2, z: 3});
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,7 @@ var fs = require('fs');
|
||||
var path = require('path');
|
||||
var pkg = require('./../../../package.json');
|
||||
var server, proxy;
|
||||
var AxiosError = require('../../../lib/core/AxiosError');
|
||||
|
||||
describe('supports http with nodejs', function () {
|
||||
|
||||
@@ -51,7 +52,7 @@ describe('supports http with nodejs', function () {
|
||||
setTimeout(function () {
|
||||
assert.equal(success, false, 'request should not succeed');
|
||||
assert.equal(failure, true, 'request should fail');
|
||||
assert.equal(error.code, 'ERR_PARSE_TIMEOUT');
|
||||
assert.equal(error.code, AxiosError.ERR_BAD_OPTION_VALUE);
|
||||
assert.equal(error.message, 'error trying to parse `config.timeout` to int');
|
||||
done();
|
||||
}, 300);
|
||||
@@ -997,7 +998,7 @@ describe('supports http with nodejs', function () {
|
||||
axios.get('http://localhost:4444/', {
|
||||
cancelToken: source.token
|
||||
}).catch(function (thrown) {
|
||||
assert.ok(thrown instanceof axios.Cancel, 'Promise must be rejected with a Cancel object');
|
||||
assert.ok(thrown instanceof axios.Cancel, 'Promise must be rejected with a CanceledError object');
|
||||
assert.equal(thrown.message, 'Operation has been canceled.');
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user