mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Moving many nodeunit tests to jasmine
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
var buildUrl = require('../../../lib/helpers/buildUrl');
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
var transformData = require('../../../lib/helpers/transformData');
|
||||
|
||||
describe('helpers::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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
var urlIsSameOrigin = require('../../../lib/helpers/urlIsSameOrigin');
|
||||
|
||||
describe('helpers::urlIsSameOrigin', function () {
|
||||
it('should detect same origin', function () {
|
||||
expect(urlIsSameOrigin(window.location.href)).toEqual(true);
|
||||
});
|
||||
|
||||
it('should detect different origin', function () {
|
||||
expect(urlIsSameOrigin('https://github.com/mzabriskie/axios')).toEqual(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user