feat: Add Be and tbd skill, also added Roadmap file

This commit is contained in:
2026-05-10 16:32:12 -04:00
parent 3500ade13f
commit 0bb8885802
29587 changed files with 10611695 additions and 0 deletions

95
Skills/@be/node_modules/axios/test/specs/__helpers.js generated vendored Normal file
View File

@@ -0,0 +1,95 @@
// Polyfill ES6 Promise
require('es6-promise').polyfill();
// Polyfill URLSearchParams
URLSearchParams = require('url-search-params');
// Import axios
axios = require('../../index');
// Jasmine config
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
jasmine.getEnv().defaultTimeoutInterval = 20000;
// Is this an old version of IE that lacks standard objects like DataView, ArrayBuffer, FormData, etc.
isOldIE = /MSIE (8|9)\.0/.test(navigator.userAgent);
// Get Ajax request using an increasing timeout to retry
getAjaxRequest = (function () {
var attempts = 0;
var MAX_ATTEMPTS = 5;
var ATTEMPT_DELAY_FACTOR = 5;
function getAjaxRequest() {
return new Promise(function (resolve, reject) {
attempts = 0;
attemptGettingAjaxRequest(resolve, reject);
});
}
function attemptGettingAjaxRequest(resolve, reject) {
var delay = attempts * attempts * ATTEMPT_DELAY_FACTOR;
if (attempts++ > MAX_ATTEMPTS) {
reject(new Error('No request was found'));
return;
}
setTimeout(function () {
var request = jasmine.Ajax.requests.mostRecent();
if (request) {
resolve(request);
} else {
attemptGettingAjaxRequest(resolve, reject);
}
}, delay);
}
return getAjaxRequest;
})();
// Validate an invalid character error
validateInvalidCharacterError = function validateInvalidCharacterError(error) {
expect(/character/i.test(error.message)).toEqual(true);
};
// Setup basic auth tests
setupBasicAuthTest = function setupBasicAuthTest() {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should accept HTTP Basic auth with username/password', function (done) {
axios('/foo', {
auth: {
username: 'Aladdin',
password: 'open sesame'
}
});
setTimeout(function () {
var request = jasmine.Ajax.requests.mostRecent();
expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==');
done();
}, 100);
});
it('should fail to encode HTTP Basic auth credentials with non-Latin1 characters', function (done) {
axios('/foo', {
auth: {
username: 'Aladßç£☃din',
password: 'open sesame'
}
}).then(function(response) {
done(new Error('Should not succeed to make a HTTP Basic auth request with non-latin1 chars in credentials.'));
}).catch(function(error) {
validateInvalidCharacterError(error);
done();
});
});
};

View File

@@ -0,0 +1,19 @@
var axios = require('../../index');
describe('adapter', function () {
it('should support custom adapter', function (done) {
var called = false;
axios('/foo', {
adapter: function (config) {
called = true;
}
});
setTimeout(function () {
expect(called).toBe(true);
done();
}, 100);
});
});

64
Skills/@be/node_modules/axios/test/specs/api.spec.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
describe('static api', function () {
it('should have request method helpers', function () {
expect(typeof axios.request).toEqual('function');
expect(typeof axios.get).toEqual('function');
expect(typeof axios.head).toEqual('function');
expect(typeof axios.options).toEqual('function');
expect(typeof axios.delete).toEqual('function');
expect(typeof axios.post).toEqual('function');
expect(typeof axios.put).toEqual('function');
expect(typeof axios.patch).toEqual('function');
});
it('should have promise method helpers', function () {
var promise = axios();
expect(typeof promise.then).toEqual('function');
expect(typeof promise.catch).toEqual('function');
});
it('should have defaults', function () {
expect(typeof axios.defaults).toEqual('object');
expect(typeof axios.defaults.headers).toEqual('object');
});
it('should have interceptors', function () {
expect(typeof axios.interceptors.request).toEqual('object');
expect(typeof axios.interceptors.response).toEqual('object');
});
it('should have all/spread helpers', function () {
expect(typeof axios.all).toEqual('function');
expect(typeof axios.spread).toEqual('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 () {
var instance = axios.create();
it('should have request methods', function () {
expect(typeof instance.request).toEqual('function');
expect(typeof instance.get).toEqual('function');
expect(typeof instance.options).toEqual('function');
expect(typeof instance.head).toEqual('function');
expect(typeof instance.delete).toEqual('function');
expect(typeof instance.post).toEqual('function');
expect(typeof instance.put).toEqual('function');
expect(typeof instance.patch).toEqual('function');
});
it('should have interceptors', function () {
expect(typeof instance.interceptors.request).toEqual('object');
expect(typeof instance.interceptors.response).toEqual('object');
});
});

View File

@@ -0,0 +1,3 @@
describe('basicAuth without btoa polyfill', function () {
setupBasicAuthTest();
});

View File

@@ -0,0 +1,20 @@
var window_btoa;
describe('basicAuth with btoa polyfill', function () {
beforeAll(function() {
window_btoa = window.btoa;
window.btoa = undefined;
});
afterAll(function() {
window.btoa = window_btoa;
window_btoa = undefined;
});
it('should not have native window.btoa', function () {
expect(window.btoa).toEqual(undefined);
});
setupBasicAuthTest();
});

View File

@@ -0,0 +1,89 @@
var Cancel = axios.Cancel;
var CancelToken = axios.CancelToken;
describe('cancel', function() {
beforeEach(function() {
jasmine.Ajax.install();
});
afterEach(function() {
jasmine.Ajax.uninstall();
});
describe('when called before sending request', function() {
it('rejects Promise with a Cancel object', function (done) {
var source = CancelToken.source();
source.cancel('Operation has been canceled.');
axios.get('/foo', {
cancelToken: source.token
}).catch(function (thrown) {
expect(thrown).toEqual(jasmine.any(Cancel));
expect(thrown.message).toBe('Operation has been canceled.');
done();
});
});
});
describe('when called after request has been sent', function() {
it('rejects Promise with a Cancel object', function (done) {
var source = CancelToken.source();
axios.get('/foo/bar', {
cancelToken: source.token
}).catch(function (thrown) {
expect(thrown).toEqual(jasmine.any(Cancel));
expect(thrown.message).toBe('Operation has been canceled.');
done();
});
getAjaxRequest().then(function (request) {
// call cancel() when the request has been sent, but a response has not been received
source.cancel('Operation has been canceled.');
request.respondWith({
status: 200,
responseText: 'OK'
});
});
});
it('calls abort on request object', function (done) {
var source = CancelToken.source();
var request;
axios.get('/foo/bar', {
cancelToken: source.token
}).catch(function() {
// jasmine-ajax sets statusText to 'abort' when request.abort() is called
expect(request.statusText).toBe('abort');
done();
});
getAjaxRequest().then(function (req) {
// call cancel() when the request has been sent, but a response has not been received
source.cancel();
request = req;
});
});
});
describe('when called after response has been received', function() {
// https://github.com/axios/axios/issues/482
it('does not cause unhandled rejection', function (done) {
var source = CancelToken.source();
axios.get('/foo', {
cancelToken: source.token
}).then(function () {
window.addEventListener('unhandledrejection', function () {
done.fail('Unhandled rejection.');
});
source.cancel();
setTimeout(done, 100);
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: 'OK'
});
});
});
});
});

View File

@@ -0,0 +1,15 @@
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.');
});
});
});

View File

@@ -0,0 +1,87 @@
var CancelToken = require('../../../lib/cancel/CancelToken');
var Cancel = require('../../../lib/cancel/Cancel');
describe('CancelToken', function() {
describe('constructor', function() {
it('throws when executor is not specified', function() {
expect(function() {
new CancelToken();
}).toThrowError(TypeError, 'executor must be a function.');
});
it('throws when executor is not a function', function() {
expect(function() {
new CancelToken(123);
}).toThrowError(TypeError, 'executor must be a function.');
});
});
describe('reason', function() {
it('returns a Cancel 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.message).toBe('Operation has been canceled.');
});
it('returns undefined if cancellation has not been requested', function() {
var token = new CancelToken(function() {});
expect(token.reason).toBeUndefined();
});
});
describe('promise', function() {
it('returns a Promise that resolves when cancellation is requested', function(done) {
var cancel;
var token = new CancelToken(function(c) {
cancel = c;
});
token.promise.then(function onFulfilled(value) {
expect(value).toEqual(jasmine.any(Cancel));
expect(value.message).toBe('Operation has been canceled.');
done();
});
cancel('Operation has been canceled.');
});
});
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
var cancel;
var token = new CancelToken(function(c) {
cancel = c;
});
cancel('Operation has been canceled.');
try {
token.throwIfRequested();
fail('Expected throwIfRequested to throw.');
} catch (thrown) {
if (!(thrown instanceof Cancel)) {
fail('Expected throwIfRequested to throw a Cancel, but it threw ' + thrown + '.');
}
expect(thrown.message).toBe('Operation has been canceled.');
}
});
it('does not throw if cancellation has not been requested', function() {
var token = new CancelToken(function() {});
token.throwIfRequested();
});
});
describe('source', function() {
it('returns an object containing token and cancel function', function() {
var source = CancelToken.source();
expect(source.token).toEqual(jasmine.any(CancelToken));
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.message).toBe('Operation has been canceled.');
});
});
});

View File

@@ -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);
});
});

View File

@@ -0,0 +1,15 @@
var createError = require('../../../lib/core/createError');
describe('core::createError', function() {
it('should create an Error with message, config, code, request and response', 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);
});
});

View File

@@ -0,0 +1,20 @@
var enhanceError = require('../../../lib/core/enhanceError');
describe('core::enhanceError', 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' } };
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);
});
it('should return error', function() {
var error = new Error('Boom!');
expect(enhanceError(error, { foo: 'bar' }, 'ESOMETHING')).toBe(error);
});
});

View File

@@ -0,0 +1,85 @@
var settle = require('../../../lib/core/settle');
describe('core::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 req = {
path: '/foo'
};
var response = {
status: 500,
config: {
validateStatus: function() {
return false;
}
},
request: req
};
settle(resolve, reject, response);
expect(resolve).not.toHaveBeenCalled();
expect(reject).toHaveBeenCalled();
var reason = reject.calls.first().args[0];
expect(reason instanceof Error).toBe(true);
expect(reason.message).toBe('Request failed with status code 500');
expect(reason.config).toBe(response.config);
expect(reason.request).toBe(req);
expect(reason.response).toBe(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);
});
});

View File

@@ -0,0 +1,30 @@
var transformData = require('../../../lib/core/transformData');
describe('core::transformData', function () {
it('should support a single transformer', function () {
var data;
data = transformData(data, null, function (data) {
data = 'foo';
return data;
});
expect(data).toEqual('foo');
});
it('should support an array of transformers', function () {
var data = '';
data = transformData(data, null, [function (data) {
data += 'f';
return data;
}, function (data) {
data += 'o';
return data;
}, function (data) {
data += 'o';
return data;
}]);
expect(data).toEqual('foo');
});
});

View File

@@ -0,0 +1,162 @@
var defaults = require('../../lib/defaults');
var utils = require('../../lib/utils');
describe('defaults', function () {
var XSRF_COOKIE_NAME = 'CUSTOM-XSRF-TOKEN';
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
delete axios.defaults.baseURL;
delete axios.defaults.headers.get['X-CUSTOM-HEADER'];
delete axios.defaults.headers.post['X-CUSTOM-HEADER'];
document.cookie = XSRF_COOKIE_NAME + '=;expires=' + new Date(Date.now() - 86400000).toGMTString();
});
it('should transform request json', function () {
expect(defaults.transformRequest[0]({foo: 'bar'})).toEqual('{"foo":"bar"}');
});
it('should do nothing to request string', function () {
expect(defaults.transformRequest[0]('foo=bar')).toEqual('foo=bar');
});
it('should transform response json', function () {
var data = defaults.transformResponse[0]('{"foo":"bar"}');
expect(typeof data).toEqual('object');
expect(data.foo).toEqual('bar');
});
it('should do nothing to response string', function () {
expect(defaults.transformResponse[0]('foo=bar')).toEqual('foo=bar');
});
it('should use global defaults config', function (done) {
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo');
done();
});
});
it('should use modified defaults config', function (done) {
axios.defaults.baseURL = 'http://example.com/';
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://example.com/foo');
done();
});
});
it('should use request config', function (done) {
axios('/foo', {
baseURL: 'http://www.example.com'
});
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://www.example.com/foo');
done();
});
});
it('should use default config for custom instance', function (done) {
var instance = axios.create({
xsrfCookieName: XSRF_COOKIE_NAME,
xsrfHeaderName: 'X-CUSTOM-XSRF-TOKEN'
});
document.cookie = instance.defaults.xsrfCookieName + '=foobarbaz';
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.requestHeaders[instance.defaults.xsrfHeaderName]).toEqual('foobarbaz');
done();
});
});
it('should use GET headers', function (done) {
axios.defaults.headers.get['X-CUSTOM-HEADER'] = 'foo';
axios.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['X-CUSTOM-HEADER']).toBe('foo');
done();
});
});
it('should use POST headers', function (done) {
axios.defaults.headers.post['X-CUSTOM-HEADER'] = 'foo';
axios.post('/foo', {});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['X-CUSTOM-HEADER']).toBe('foo');
done();
});
});
it('should use header config', function (done) {
var instance = axios.create({
headers: {
common: {
'X-COMMON-HEADER': 'commonHeaderValue'
},
get: {
'X-GET-HEADER': 'getHeaderValue'
},
post: {
'X-POST-HEADER': 'postHeaderValue'
}
}
});
instance.get('/foo', {
headers: {
'X-FOO-HEADER': 'fooHeaderValue',
'X-BAR-HEADER': 'barHeaderValue'
}
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders).toEqual(
utils.merge(defaults.headers.common, defaults.headers.get, {
'X-COMMON-HEADER': 'commonHeaderValue',
'X-GET-HEADER': 'getHeaderValue',
'X-FOO-HEADER': 'fooHeaderValue',
'X-BAR-HEADER': 'barHeaderValue'
})
);
done();
});
});
it('should be used by custom instance if set before instance created', function (done) {
axios.defaults.baseURL = 'http://example.org/';
var instance = axios.create();
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://example.org/foo');
done();
});
});
it('should be used by custom instance if set after instance created', function (done) {
var instance = axios.create();
axios.defaults.baseURL = 'http://example.org/';
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://example.org/foo');
done();
});
});
});

View File

@@ -0,0 +1,89 @@
function testHeaderValue(headers, key, val) {
var found = false;
for (var k in headers) {
if (k.toLowerCase() === key.toLowerCase()) {
found = true;
expect(headers[k]).toEqual(val);
break;
}
}
if (!found) {
if (typeof val === 'undefined') {
expect(headers.hasOwnProperty(key)).toEqual(false);
} else {
throw new Error(key + ' was not found in headers');
}
}
}
describe('headers', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should default common headers', function (done) {
var headers = axios.defaults.headers.common;
axios('/foo');
getAjaxRequest().then(function (request) {
for (var key in headers) {
if (headers.hasOwnProperty(key)) {
expect(request.requestHeaders[key]).toEqual(headers[key]);
}
}
done();
});
});
it('should add extra headers for post', function (done) {
var headers = axios.defaults.headers.common;
axios.post('/foo', 'fizz=buzz');
getAjaxRequest().then(function (request) {
for (var key in headers) {
if (headers.hasOwnProperty(key)) {
expect(request.requestHeaders[key]).toEqual(headers[key]);
}
}
done();
});
});
it('should use application/json when posting an object', function (done) {
axios.post('/foo/bar', {
firstName: 'foo',
lastName: 'bar'
});
getAjaxRequest().then(function (request) {
testHeaderValue(request.requestHeaders, 'Content-Type', 'application/json;charset=utf-8');
done();
});
});
it('should remove content-type if data is empty', function (done) {
axios.post('/foo');
getAjaxRequest().then(function (request) {
testHeaderValue(request.requestHeaders, 'Content-Type', undefined);
done();
});
});
it('should preserve content-type if data is false', function (done) {
axios.post('/foo', false);
getAjaxRequest().then(function (request) {
testHeaderValue(request.requestHeaders, 'Content-Type', 'application/x-www-form-urlencoded');
done();
});
});
});

View File

@@ -0,0 +1,12 @@
var bind = require('../../../lib/helpers/bind');
describe('bind', function () {
it('should bind an object to a function', function () {
var o = { val: 123 };
var f = bind(function (num) {
return this.val * num;
}, o);
expect(f(2)).toEqual(246);
});
});

View File

@@ -0,0 +1,26 @@
var __btoa = require('../../../lib/helpers/btoa');
describe('btoa polyfill', function () {
it('should behave the same as native window.btoa', function () {
// btoa doesn't exist in IE8/9
if (isOldIE && typeof Int8Array === 'undefined') {
return;
}
var data = 'Hello, world';
expect(__btoa(data)).toEqual(window.btoa(data));
});
it('should throw an error if char is out of range 0xFF', function () {
var err;
var data = 'I ♡ Unicode!';
try {
__btoa(data);
} catch (e) {
err = e;
}
validateInvalidCharacterError(err);
});
});

View File

@@ -0,0 +1,69 @@
var buildURL = require('../../../lib/helpers/buildURL');
var URLSearchParams = require('url-search-params');
describe('helpers::buildURL', function () {
it('should support null params', function () {
expect(buildURL('/foo')).toEqual('/foo');
});
it('should support params', function () {
expect(buildURL('/foo', {
foo: 'bar'
})).toEqual('/foo?foo=bar');
});
it('should support object params', function () {
expect(buildURL('/foo', {
foo: {
bar: 'baz'
}
})).toEqual('/foo?foo=' + encodeURI('{"bar":"baz"}'));
});
it('should support date params', function () {
var date = new Date();
expect(buildURL('/foo', {
date: date
})).toEqual('/foo?date=' + date.toISOString());
});
it('should support array params', function () {
expect(buildURL('/foo', {
foo: ['bar', 'baz']
})).toEqual('/foo?foo[]=bar&foo[]=baz');
});
it('should support special char params', function () {
expect(buildURL('/foo', {
foo: '@:$, '
})).toEqual('/foo?foo=@:$,+');
});
it('should support existing params', function () {
expect(buildURL('/foo?foo=bar', {
bar: 'baz'
})).toEqual('/foo?foo=bar&bar=baz');
});
it('should support "length" parameter', function () {
expect(buildURL('/foo', {
query: 'bar',
start: 0,
length: 5
})).toEqual('/foo?query=bar&start=0&length=5');
});
it('should use serializer if provided', function () {
serializer = sinon.stub();
params = {foo: 'bar'};
serializer.returns('foo=bar');
expect(buildURL('/foo', params, serializer)).toEqual('/foo?foo=bar');
expect(serializer.calledOnce).toBe(true);
expect(serializer.calledWith(params)).toBe(true);
});
it('should support URLSearchParams', function () {
expect(buildURL('/foo', new URLSearchParams('bar=baz'))).toEqual('/foo?bar=baz');
});
});

View File

@@ -0,0 +1,23 @@
var combineURLs = require('../../../lib/helpers/combineURLs');
describe('helpers::combineURLs', function () {
it('should combine URLs', function () {
expect(combineURLs('https://api.github.com', '/users')).toBe('https://api.github.com/users');
});
it('should remove duplicate slashes', function () {
expect(combineURLs('https://api.github.com/', '/users')).toBe('https://api.github.com/users');
});
it('should insert missing slash', function () {
expect(combineURLs('https://api.github.com', 'users')).toBe('https://api.github.com/users');
});
it('should not insert slash when relative url missing/empty', function () {
expect(combineURLs('https://api.github.com/users', '')).toBe('https://api.github.com/users');
});
it('should allow a single slash for relative url', function () {
expect(combineURLs('https://api.github.com/users', '/')).toBe('https://api.github.com/users/');
});
});

View File

@@ -0,0 +1,36 @@
var cookies = require('../../../lib/helpers/cookies');
describe('helpers::cookies', function () {
afterEach(function () {
// Remove all the cookies
var expires = Date.now() - (60 * 60 * 24 * 7);
document.cookie.split(';').map(function (cookie) {
return cookie.split('=')[0];
}).forEach(function (name) {
document.cookie = name + '=; expires=' + new Date(expires).toGMTString();
});
});
it('should write cookies', function () {
cookies.write('foo', 'baz');
expect(document.cookie).toEqual('foo=baz');
});
it('should read cookies', function () {
cookies.write('foo', 'abc');
cookies.write('bar', 'def');
expect(cookies.read('foo')).toEqual('abc');
expect(cookies.read('bar')).toEqual('def');
});
it('should remove cookies', function () {
cookies.write('foo', 'bar');
cookies.remove('foo');
expect(cookies.read('foo')).toEqual(null);
});
it('should uri encode values', function () {
cookies.write('foo', 'bar baz%');
expect(document.cookie).toEqual('foo=bar%20baz%25');
});
});

View File

@@ -0,0 +1,23 @@
var isAbsoluteURL = require('../../../lib/helpers/isAbsoluteURL');
describe('helpers::isAbsoluteURL', function () {
it('should return true if URL begins with valid scheme name', function () {
expect(isAbsoluteURL('https://api.github.com/users')).toBe(true);
expect(isAbsoluteURL('custom-scheme-v1.0://example.com/')).toBe(true);
expect(isAbsoluteURL('HTTP://example.com/')).toBe(true);
});
it('should return false if URL begins with invalid scheme name', function () {
expect(isAbsoluteURL('123://example.com/')).toBe(false);
expect(isAbsoluteURL('!valid://example.com/')).toBe(false);
});
it('should return true if URL is protocol-relative', function () {
expect(isAbsoluteURL('//example.com/')).toBe(true);
});
it('should return false if URL is relative', function () {
expect(isAbsoluteURL('/foo')).toBe(false);
expect(isAbsoluteURL('foo')).toBe(false);
});
});

View File

@@ -0,0 +1,11 @@
var isURLSameOrigin = require('../../../lib/helpers/isURLSameOrigin');
describe('helpers::isURLSameOrigin', function () {
it('should detect same origin', function () {
expect(isURLSameOrigin(window.location.href)).toEqual(true);
});
it('should detect different origin', function () {
expect(isURLSameOrigin('https://github.com/axios/axios')).toEqual(false);
});
});

View File

@@ -0,0 +1,21 @@
var normalizeHeaderName = require('../../../lib/helpers/normalizeHeaderName');
describe('helpers::normalizeHeaderName', function () {
it('should normalize matching header name', function () {
var headers = {
'conTenT-Type': 'foo/bar',
};
normalizeHeaderName(headers, 'Content-Type');
expect(headers['Content-Type']).toBe('foo/bar');
expect(headers['conTenT-Type']).toBeUndefined();
});
it('should not change non-matching header name', function () {
var headers = {
'content-type': 'foo/bar',
};
normalizeHeaderName(headers, 'Content-Length');
expect(headers['content-type']).toBe('foo/bar');
expect(headers['Content-Length']).toBeUndefined();
});
});

View File

@@ -0,0 +1,45 @@
var parseHeaders = require('../../../lib/helpers/parseHeaders');
describe('helpers::parseHeaders', function () {
it('should parse headers', function () {
var date = new Date();
var parsed = parseHeaders(
'Date: ' + date.toISOString() + '\n' +
'Content-Type: application/json\n' +
'Connection: keep-alive\n' +
'Transfer-Encoding: chunked'
);
expect(parsed['date']).toEqual(date.toISOString());
expect(parsed['content-type']).toEqual('application/json');
expect(parsed['connection']).toEqual('keep-alive');
expect(parsed['transfer-encoding']).toEqual('chunked');
});
it('should use array for set-cookie', function() {
var parsedZero = parseHeaders('');
var parsedSingle = parseHeaders(
'Set-Cookie: key=val;'
);
var parsedMulti = parseHeaders(
'Set-Cookie: key=val;\n' +
'Set-Cookie: key2=val2;\n'
);
expect(parsedZero['set-cookie']).toBeUndefined();
expect(parsedSingle['set-cookie']).toEqual(['key=val;']);
expect(parsedMulti['set-cookie']).toEqual(['key=val;', 'key2=val2;']);
});
it('should handle duplicates', function() {
var parsed = parseHeaders(
'Age: age-a\n' + // age is in ignore duplicates blacklist
'Age: age-b\n' +
'Foo: foo-a\n' +
'Foo: foo-b\n'
);
expect(parsed['age']).toEqual('age-a');
expect(parsed['foo']).toEqual('foo-a, foo-b');
});
});

View File

@@ -0,0 +1,21 @@
var spread = require('../../../lib/helpers/spread');
describe('helpers::spread', function () {
it('should spread array to arguments', function () {
var value = 0;
spread(function (a, b) {
value = a * b;
})([5, 10]);
expect(value).toEqual(50);
});
it('should return callback result', function () {
var value = spread(function (a, b) {
return a * b;
})([5, 10]);
expect(value).toEqual(50);
});
});

View File

@@ -0,0 +1,100 @@
describe('instance', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should have the same methods as default instance', function () {
var instance = axios.create();
for (var prop in axios) {
if ([
'Axios',
'create',
'Cancel',
'CancelToken',
'isCancel',
'all',
'spread',
'default'].indexOf(prop) > -1) {
continue;
}
expect(typeof instance[prop]).toBe(typeof axios[prop]);
}
});
it('should make an http request without verb helper', function (done) {
var instance = axios.create();
instance('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo');
done();
});
});
it('should make an http request', function (done) {
var instance = axios.create();
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo');
done();
});
});
it('should use instance options', function (done) {
var instance = axios.create({ timeout: 1000 });
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.timeout).toBe(1000);
done();
});
});
it('should have defaults.headers', function () {
var instance = axios.create({
baseURL: 'https://api.example.com'
});
expect(typeof instance.defaults.headers, 'object');
expect(typeof instance.defaults.headers.common, 'object');
});
it('should have interceptors on the instance', function (done) {
axios.interceptors.request.use(function (config) {
config.foo = true;
return config;
});
var instance = axios.create();
instance.interceptors.request.use(function (config) {
config.bar = true;
return config;
});
var response;
instance.get('/foo').then(function (res) {
response = res;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200
});
setTimeout(function () {
expect(response.config.foo).toEqual(undefined);
expect(response.config.bar).toEqual(true);
done();
}, 100);
});
});
});

View File

@@ -0,0 +1,273 @@
describe('interceptors', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
axios.interceptors.request.handlers = [];
axios.interceptors.response.handlers = [];
});
it('should add a request interceptor', function (done) {
axios.interceptors.request.use(function (config) {
config.headers.test = 'added by interceptor';
return config;
});
axios('/foo');
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: 'OK'
});
expect(request.requestHeaders.test).toBe('added by interceptor');
done();
});
});
it('should add a request interceptor that returns a new config object', function (done) {
axios.interceptors.request.use(function () {
return {
url: '/bar',
method: 'post'
};
});
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.method).toBe('POST');
expect(request.url).toBe('/bar');
done();
});
});
it('should add a request interceptor that returns a promise', function (done) {
axios.interceptors.request.use(function (config) {
return new Promise(function (resolve) {
// do something async
setTimeout(function () {
config.headers.async = 'promise';
resolve(config);
}, 100);
});
});
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.requestHeaders.async).toBe('promise');
done();
});
});
it('should add multiple request interceptors', function (done) {
axios.interceptors.request.use(function (config) {
config.headers.test1 = '1';
return config;
});
axios.interceptors.request.use(function (config) {
config.headers.test2 = '2';
return config;
});
axios.interceptors.request.use(function (config) {
config.headers.test3 = '3';
return config;
});
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.requestHeaders.test1).toBe('1');
expect(request.requestHeaders.test2).toBe('2');
expect(request.requestHeaders.test3).toBe('3');
done();
});
});
it('should add a response interceptor', function (done) {
var response;
axios.interceptors.response.use(function (data) {
data.data = data.data + ' - modified by interceptor';
return data;
});
axios('/foo').then(function (data) {
response = data;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: 'OK'
});
setTimeout(function () {
expect(response.data).toBe('OK - modified by interceptor');
done();
}, 100);
});
});
it('should add a response interceptor that returns a new data object', function (done) {
var response;
axios.interceptors.response.use(function () {
return {
data: 'stuff'
};
});
axios('/foo').then(function (data) {
response = data;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: 'OK'
});
setTimeout(function () {
expect(response.data).toBe('stuff');
done();
}, 100);
});
});
it('should add a response interceptor that returns a promise', function (done) {
var response;
axios.interceptors.response.use(function (data) {
return new Promise(function (resolve) {
// do something async
setTimeout(function () {
data.data = 'you have been promised!';
resolve(data);
}, 10);
});
});
axios('/foo').then(function (data) {
response = data;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: 'OK'
});
setTimeout(function () {
expect(response.data).toBe('you have been promised!');
done();
}, 100);
});
});
it('should add multiple response interceptors', function (done) {
var response;
axios.interceptors.response.use(function (data) {
data.data = data.data + '1';
return data;
});
axios.interceptors.response.use(function (data) {
data.data = data.data + '2';
return data;
});
axios.interceptors.response.use(function (data) {
data.data = data.data + '3';
return data;
});
axios('/foo').then(function (data) {
response = data;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: 'OK'
});
setTimeout(function () {
expect(response.data).toBe('OK123');
done();
}, 100);
});
});
it('should allow removing interceptors', function (done) {
var response, intercept;
axios.interceptors.response.use(function (data) {
data.data = data.data + '1';
return data;
});
intercept = axios.interceptors.response.use(function (data) {
data.data = data.data + '2';
return data;
});
axios.interceptors.response.use(function (data) {
data.data = data.data + '3';
return data;
});
axios.interceptors.response.eject(intercept);
axios('/foo').then(function (data) {
response = data;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: 'OK'
});
setTimeout(function () {
expect(response.data).toBe('OK13');
done();
}, 100);
});
});
it('should execute interceptors before transformers', function (done) {
axios.interceptors.request.use(function (config) {
config.data.baz = 'qux';
return config;
});
axios.post('/foo', {
foo: 'bar'
});
getAjaxRequest().then(function (request) {
expect(request.params).toEqual('{"foo":"bar","baz":"qux"}');
done();
});
});
it('should modify base URL in request interceptor', function (done) {
var instance = axios.create({
baseURL: 'http://test.com/'
});
instance.interceptors.request.use(function (config) {
config.baseURL = 'http://rebase.com/';
return config;
});
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://rebase.com/foo');
done();
});
});
});

View File

@@ -0,0 +1,84 @@
describe('options', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should default method to get', function (done) {
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.method).toBe('GET');
done();
});
});
it('should accept headers', function (done) {
axios('/foo', {
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['X-Requested-With']).toEqual('XMLHttpRequest');
done();
});
});
it('should accept params', function (done) {
axios('/foo', {
params: {
foo: 123,
bar: 456
}
});
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo?foo=123&bar=456');
done();
});
});
it('should allow overriding default headers', function (done) {
axios('/foo', {
headers: {
'Accept': 'foo/bar'
}
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['Accept']).toEqual('foo/bar');
done();
});
});
it('should accept base URL', function (done) {
var instance = axios.create({
baseURL: 'http://test.com/'
});
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://test.com/foo');
done();
});
});
it('should ignore base URL if request URL is absolute', function (done) {
var instance = axios.create({
baseURL: 'http://someurl.com/'
});
instance.get('http://someotherurl.com/');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://someotherurl.com/');
done();
});
});
});

View File

@@ -0,0 +1,111 @@
describe('progress events', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should add a download progress handler', function (done) {
var progressSpy = jasmine.createSpy('progress');
axios('/foo', { onDownloadProgress: progressSpy } );
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: '{"foo": "bar"}'
});
expect(progressSpy).toHaveBeenCalled();
done();
});
});
it('should add a upload progress handler', function (done) {
var progressSpy = jasmine.createSpy('progress');
axios('/foo', { onUploadProgress: progressSpy } );
getAjaxRequest().then(function (request) {
// Jasmine AJAX doesn't trigger upload events. Waiting for upstream fix
// expect(progressSpy).toHaveBeenCalled();
done();
});
});
it('should add both upload and download progress handlers', function (done) {
var downloadProgressSpy = jasmine.createSpy('downloadProgress');
var uploadProgressSpy = jasmine.createSpy('uploadProgress');
axios('/foo', { onDownloadProgress: downloadProgressSpy, onUploadProgress: uploadProgressSpy });
getAjaxRequest().then(function (request) {
// expect(uploadProgressSpy).toHaveBeenCalled();
expect(downloadProgressSpy).not.toHaveBeenCalled();
request.respondWith({
status: 200,
responseText: '{"foo": "bar"}'
});
expect(downloadProgressSpy).toHaveBeenCalled();
done();
});
});
it('should add a download progress handler from instance config', function (done) {
var progressSpy = jasmine.createSpy('progress');
var instance = axios.create({
onDownloadProgress: progressSpy,
});
instance.get('/foo');
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: '{"foo": "bar"}'
});
expect(progressSpy).toHaveBeenCalled();
done();
});
});
it('should add a upload progress handler from instance config', function (done) {
var progressSpy = jasmine.createSpy('progress');
var instance = axios.create({
onUploadProgress: progressSpy,
});
instance.get('/foo');
getAjaxRequest().then(function (request) {
// expect(progressSpy).toHaveBeenCalled();
done();
});
});
it('should add upload and download progress handlers from instance config', function (done) {
var downloadProgressSpy = jasmine.createSpy('downloadProgress');
var uploadProgressSpy = jasmine.createSpy('uploadProgress');
var instance = axios.create({
onDownloadProgress: downloadProgressSpy,
onUploadProgress: uploadProgressSpy,
});
instance.get('/foo');
getAjaxRequest().then(function (request) {
// expect(uploadProgressSpy).toHaveBeenCalled();
expect(downloadProgressSpy).not.toHaveBeenCalled();
request.respondWith({
status: 200,
responseText: '{"foo": "bar"}'
});
expect(downloadProgressSpy).toHaveBeenCalled();
done();
});
});
});

View File

@@ -0,0 +1,70 @@
describe('promise', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should provide succinct object to then', function (done) {
var response;
axios('/foo').then(function (r) {
response = r;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: '{"hello":"world"}'
});
setTimeout(function () {
expect(typeof response).toEqual('object');
expect(response.data.hello).toEqual('world');
expect(response.status).toEqual(200);
expect(response.headers['content-type']).toEqual('application/json');
expect(response.config.url).toEqual('/foo');
done();
}, 100);
});
});
it('should support all', function (done) {
var fulfilled = false;
axios.all([true, 123]).then(function () {
fulfilled = true;
});
setTimeout(function () {
expect(fulfilled).toEqual(true);
done();
}, 100);
});
it('should support spread', function (done) {
var sum = 0;
var fulfilled = false;
var result;
axios
.all([123, 456])
.then(axios.spread(function (a, b) {
sum = a + b;
fulfilled = true;
return 'hello world';
}))
.then(function (res) {
result = res;
});
setTimeout(function () {
expect(fulfilled).toEqual(true);
expect(sum).toEqual(123 + 456);
expect(result).toEqual('hello world');
done();
}, 100);
});
});

View File

@@ -0,0 +1,357 @@
describe('requests', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should treat single string arg as url', function (done) {
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo');
expect(request.method).toBe('GET');
done();
});
});
it('should treat method value as lowercase string', function (done) {
axios({
url: '/foo',
method: 'POST'
}).then(function (response) {
expect(response.config.method).toBe('post');
done();
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200
});
});
});
it('should allow string arg as url, and config arg', function (done) {
axios.post('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo');
expect(request.method).toBe('POST');
done();
});
});
it('should make an http request', function (done) {
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo');
done();
});
});
it('should reject on network errors', function (done) {
// disable jasmine.Ajax since we're hitting a non-existant server anyway
jasmine.Ajax.uninstall();
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
var finish = function () {
expect(resolveSpy).not.toHaveBeenCalled();
expect(rejectSpy).toHaveBeenCalled();
var reason = rejectSpy.calls.first().args[0];
expect(reason instanceof Error).toBe(true);
expect(reason.config.method).toBe('get');
expect(reason.config.url).toBe('http://thisisnotaserver/foo');
expect(reason.request).toEqual(jasmine.any(XMLHttpRequest));
// re-enable jasmine.Ajax
jasmine.Ajax.install();
done();
};
axios('http://thisisnotaserver/foo')
.then(resolveSpy, rejectSpy)
.then(finish, finish);
});
it('should reject when validateStatus returns false', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
axios('/foo', {
validateStatus: function (status) {
return status !== 500;
}
}).then(resolveSpy)
.catch(rejectSpy)
.then(function () {
expect(resolveSpy).not.toHaveBeenCalled();
expect(rejectSpy).toHaveBeenCalled();
var reason = rejectSpy.calls.first().args[0];
expect(reason instanceof Error).toBe(true);
expect(reason.message).toBe('Request failed with status code 500');
expect(reason.config.method).toBe('get');
expect(reason.config.url).toBe('/foo');
expect(reason.response.status).toBe(500);
done();
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 500
});
});
});
it('should resolve when validateStatus returns true', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
axios('/foo', {
validateStatus: function (status) {
return status === 500;
}
}).then(resolveSpy)
.catch(rejectSpy)
.then(function () {
expect(resolveSpy).toHaveBeenCalled();
expect(rejectSpy).not.toHaveBeenCalled();
done();
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 500
});
});
});
// https://github.com/axios/axios/issues/378
it('should return JSON when rejecting', function (done) {
var response;
axios('/api/account/signup', {
username: null,
password: null
}, {
method: 'post',
headers: {
'Accept': 'application/json'
}
})
.catch(function (error) {
response = error.response;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 400,
statusText: 'Bad Request',
responseText: '{"error": "BAD USERNAME", "code": 1}'
});
setTimeout(function () {
expect(typeof response.data).toEqual('object');
expect(response.data.error).toEqual('BAD USERNAME');
expect(response.data.code).toEqual(1);
done();
}, 100);
});
});
it('should make cross domian http request', function (done) {
var response;
axios.post('www.someurl.com/foo').then(function(res){
response = res;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
statusText: 'OK',
responseText: '{"foo": "bar"}',
headers: {
'Content-Type': 'application/json'
}
});
setTimeout(function () {
expect(response.data.foo).toEqual('bar');
expect(response.status).toEqual(200);
expect(response.statusText).toEqual('OK');
expect(response.headers['content-type']).toEqual('application/json');
done();
}, 100);
});
});
it('should supply correct response', function (done) {
var response;
axios.post('/foo').then(function (res) {
response = res;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
statusText: 'OK',
responseText: '{"foo": "bar"}',
headers: {
'Content-Type': 'application/json'
}
});
setTimeout(function () {
expect(response.data.foo).toEqual('bar');
expect(response.status).toEqual(200);
expect(response.statusText).toEqual('OK');
expect(response.headers['content-type']).toEqual('application/json');
done();
}, 100);
});
});
// https://github.com/axios/axios/issues/201
it('should fix IE no content error', function (done) {
var response;
axios('/foo').then(function (res) {
response = res
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 1223,
statusText: 'Unknown'
});
setTimeout(function () {
expect(response.status).toEqual(204);
expect(response.statusText).toEqual('No Content');
done();
}, 100);
});
});
it('should allow overriding Content-Type header case-insensitive', function (done) {
var response;
var contentType = 'application/vnd.myapp.type+json';
axios.post('/foo', { prop: 'value' }, {
headers: {
'content-type': contentType
}
}).then(function (res) {
response = res;
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['Content-Type']).toEqual(contentType);
done();
});
});
it('should support binary data as array buffer', function (done) {
// Int8Array doesn't exist in IE8/9
if (isOldIE && typeof Int8Array === 'undefined') {
done();
return;
}
var input = new Int8Array(2);
input[0] = 1;
input[1] = 2;
axios.post('/foo', input.buffer);
getAjaxRequest().then(function (request) {
var output = new Int8Array(request.params);
expect(output.length).toEqual(2);
expect(output[0]).toEqual(1);
expect(output[1]).toEqual(2);
done();
});
});
it('should support binary data as array buffer view', function (done) {
// Int8Array doesn't exist in IE8/9
if (isOldIE && typeof Int8Array === 'undefined') {
done();
return;
}
var input = new Int8Array(2);
input[0] = 1;
input[1] = 2;
axios.post('/foo', input);
getAjaxRequest().then(function (request) {
var output = new Int8Array(request.params);
expect(output.length).toEqual(2);
expect(output[0]).toEqual(1);
expect(output[1]).toEqual(2);
done();
});
});
it('should support array buffer response', function (done) {
// ArrayBuffer doesn't exist in IE8/9
if (isOldIE && typeof ArrayBuffer === 'undefined') {
done();
return;
}
var response;
function str2ab(str) {
var buff = new ArrayBuffer(str.length * 2);
var view = new Uint16Array(buff);
for ( var i=0, l=str.length; i<l; i++) {
view[i] = str.charCodeAt(i);
}
return buff;
}
axios('/foo', {
responseType: 'arraybuffer'
}).then(function (data) {
response = data;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
response: str2ab('Hello world')
});
setTimeout(function () {
expect(response.data.byteLength).toBe(22);
done();
}, 100);
});
});
it('should support URLSearchParams', function (done) {
var params = new URLSearchParams();
params.append('param1', 'value1');
params.append('param2', 'value2');
axios.post('/foo', params);
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['Content-Type']).toBe('application/x-www-form-urlencoded;charset=utf-8');
expect(request.params).toBe('param1=value1&param2=value2');
done();
});
});
});

View File

@@ -0,0 +1,94 @@
describe('transform', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should transform JSON to string', function (done) {
var data = {
foo: 'bar'
};
axios.post('/foo', data);
getAjaxRequest().then(function (request) {
expect(request.params).toEqual('{"foo":"bar"}');
done();
});
});
it('should transform string to JSON', function (done) {
var response;
axios('/foo').then(function (data) {
response = data;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: '{"foo": "bar"}'
});
setTimeout(function () {
expect(typeof response.data).toEqual('object');
expect(response.data.foo).toEqual('bar');
done();
}, 100);
});
});
it('should override default transform', function (done) {
var data = {
foo: 'bar'
};
axios.post('/foo', data, {
transformRequest: function (data) {
return data;
}
});
getAjaxRequest().then(function (request) {
expect(typeof request.params).toEqual('object');
done();
});
});
it('should allow an Array of transformers', function (done) {
var data = {
foo: 'bar'
};
axios.post('/foo', data, {
transformRequest: axios.defaults.transformRequest.concat(
function (data) {
return data.replace('bar', 'baz');
}
)
});
getAjaxRequest().then(function (request) {
expect(request.params).toEqual('{"foo":"baz"}');
done();
});
});
it('should allowing mutating headers', function (done) {
var token = Math.floor(Math.random() * Math.pow(2, 64)).toString(36);
axios('/foo', {
transformRequest: function (data, headers) {
headers['X-Authorization'] = token;
}
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['X-Authorization']).toEqual(token);
done();
});
});
});

View File

@@ -0,0 +1,34 @@
var extend = require('../../../lib/utils').extend;
describe('utils::extend', function () {
it('should be mutable', function () {
var a = {};
var b = {foo: 123};
extend(a, b);
expect(a.foo).toEqual(b.foo);
});
it('should extend properties', function () {
var a = {foo: 123, bar: 456};
var b = {bar: 789};
a = extend(a, b);
expect(a.foo).toEqual(123);
expect(a.bar).toEqual(789);
});
it('should bind to thisArg', function () {
var a = {};
var b = {getFoo: function getFoo() { return this.foo; }};
var thisArg = { foo: 'barbaz' };
extend(a, b, thisArg);
expect(typeof a.getFoo).toEqual('function');
expect(a.getFoo()).toEqual(thisArg.foo);
});
});

View File

@@ -0,0 +1,63 @@
var forEach = require('../../../lib/utils').forEach;
describe('utils::forEach', function () {
it('should loop over an array', function () {
var sum = 0;
forEach([1, 2, 3, 4, 5], function (val) {
sum += val;
});
expect(sum).toEqual(15);
});
it('should loop over object keys', function () {
var keys = '';
var vals = 0;
var obj = {
b: 1,
a: 2,
r: 3
};
forEach(obj, function (v, k) {
keys += k;
vals += v;
});
expect(keys).toEqual('bar');
expect(vals).toEqual(6);
});
it('should handle undefined gracefully', function () {
var count = 0;
forEach(undefined, function () {
count++;
});
expect(count).toEqual(0);
});
it('should make an array out of non-array argument', function () {
var count = 0;
forEach(function () {}, function () {
count++;
});
expect(count).toEqual(1);
});
it('should handle non object prototype gracefully', function () {
var count = 0;
var data = Object.create(null);
data.foo = 'bar'
forEach(data, function () {
count++;
});
expect(count).toEqual(1);
});
});

View File

@@ -0,0 +1,86 @@
var utils = require('../../../lib/utils');
var Stream = require('stream');
describe('utils::isX', function () {
it('should validate Array', function () {
expect(utils.isArray([])).toEqual(true);
expect(utils.isArray({length: 5})).toEqual(false);
});
it('should validate ArrayBuffer', function () {
// ArrayBuffer doesn't exist in IE8/9
if (isOldIE && typeof ArrayBuffer === 'undefined') {
return;
}
expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true);
expect(utils.isArrayBuffer({})).toEqual(false);
});
it('should validate ArrayBufferView', function () {
// ArrayBuffer doesn't exist in IE8/9
if (isOldIE && typeof ArrayBuffer === 'undefined') {
return;
}
expect(utils.isArrayBufferView(new DataView(new ArrayBuffer(2)))).toEqual(true);
});
it('should validate FormData', function () {
// FormData doesn't exist in IE8/9
if (isOldIE && typeof FormData === 'undefined') {
return;
}
expect(utils.isFormData(new FormData())).toEqual(true);
});
it('should validate Blob', function () {
// Blob doesn't exist in IE8/9
if (isOldIE && typeof Blob === 'undefined') {
return;
}
expect(utils.isBlob(new Blob())).toEqual(true);
});
it('should validate String', function () {
expect(utils.isString('')).toEqual(true);
expect(utils.isString({toString: function () { return ''; }})).toEqual(false);
});
it('should validate Number', function () {
expect(utils.isNumber(123)).toEqual(true);
expect(utils.isNumber('123')).toEqual(false);
});
it('should validate Undefined', function () {
expect(utils.isUndefined()).toEqual(true);
expect(utils.isUndefined(null)).toEqual(false);
});
it('should validate Object', function () {
expect(utils.isObject({})).toEqual(true);
expect(utils.isObject(null)).toEqual(false);
});
it('should validate Date', function () {
expect(utils.isDate(new Date())).toEqual(true);
expect(utils.isDate(Date.now())).toEqual(false);
});
it('should validate Function', function () {
expect(utils.isFunction(function () {})).toEqual(true);
expect(utils.isFunction('function')).toEqual(false);
});
it('should validate Stream', function () {
expect(utils.isStream(new Stream.Readable())).toEqual(true);
expect(utils.isStream({ foo: 'bar' })).toEqual(false);
});
it('should validate URLSearchParams', function () {
expect(utils.isURLSearchParams(new URLSearchParams())).toEqual(true);
expect(utils.isURLSearchParams('foo=1&bar=2')).toEqual(false);
});
});

View File

@@ -0,0 +1,42 @@
var merge = require('../../../lib/utils').merge;
describe('utils::merge', function () {
it('should be immutable', function () {
var a = {};
var b = {foo: 123};
var c = {bar: 456};
merge(a, b, c);
expect(typeof a.foo).toEqual('undefined');
expect(typeof a.bar).toEqual('undefined');
expect(typeof b.bar).toEqual('undefined');
expect(typeof c.foo).toEqual('undefined');
});
it('should merge properties', function () {
var a = {foo: 123};
var b = {bar: 456};
var c = {foo: 789};
var d = merge(a, b, c);
expect(d.foo).toEqual(789);
expect(d.bar).toEqual(456);
});
it('should merge recursively', function () {
var a = {foo: {bar: 123}};
var b = {foo: {baz: 456}, bar: {qux: 789}};
expect(merge(a, b)).toEqual({
foo: {
bar: 123,
baz: 456
},
bar: {
qux: 789
}
});
});
});

View File

@@ -0,0 +1,12 @@
var trim = require('../../../lib/utils').trim;
describe('utils::trim', function () {
it('should trim spaces', function () {
expect(trim(' foo ')).toEqual('foo');
});
it('should trim tabs', function () {
expect(trim('\tfoo\t')).toEqual('foo');
});
});

82
Skills/@be/node_modules/axios/test/specs/xsrf.spec.js generated vendored Normal file
View File

@@ -0,0 +1,82 @@
var cookies = require('../../lib/helpers/cookies');
describe('xsrf', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
document.cookie = axios.defaults.xsrfCookieName + '=;expires=' + new Date(Date.now() - 86400000).toGMTString();
jasmine.Ajax.uninstall();
});
it('should not set xsrf header if cookie is null', function (done) {
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual(undefined);
done();
});
});
it('should set xsrf header if cookie is set', function (done) {
document.cookie = axios.defaults.xsrfCookieName + '=12345';
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual('12345');
done();
});
});
it('should not set xsrf header if xsrfCookieName is null', function (done) {
document.cookie = axios.defaults.xsrfCookieName + '=12345';
axios('/foo', {
xsrfCookieName: null
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual(undefined);
done();
});
});
it('should not read cookies at all if xsrfCookieName is null', function (done) {
spyOn(cookies, "read");
axios('/foo', {
xsrfCookieName: null
});
getAjaxRequest().then(function (request) {
expect(cookies.read).not.toHaveBeenCalled();
done();
});
});
it('should not set xsrf header for cross origin', function (done) {
document.cookie = axios.defaults.xsrfCookieName + '=12345';
axios('http://example.com/');
getAjaxRequest().then(function (request) {
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual(undefined);
done();
});
});
it('should set xsrf header for cross origin when using withCredentials', function (done) {
document.cookie = axios.defaults.xsrfCookieName + '=12345';
axios('http://example.com/', {
withCredentials: true
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual('12345');
done();
});
});
});