2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

Moving many nodeunit tests to jasmine

This commit is contained in:
mzabriskie
2015-03-18 17:12:51 -06:00
parent b745600ab7
commit fc12b933f7
19 changed files with 264 additions and 260 deletions
+64
View File
@@ -0,0 +1,64 @@
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 arguments', function () {
var sum = 0;
(function () {
forEach(arguments, function (val) {
sum += val;
});
})(1, 2, 3, 4, 5);
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);
});
});
+52
View File
@@ -0,0 +1,52 @@
var utils = require('../../../lib/utils');
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 () {
expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true);
expect(utils.isArrayBuffer({})).toEqual(false);
});
it('should validate ArrayBufferView', function () {
expect(utils.isArrayBufferView(new DataView(new ArrayBuffer(2)))).toEqual(true);
});
it('should validate FormData', function () {
expect(utils.isFormData(new FormData())).toEqual(true);
});
// TODO Blob is not a constructor in PhantomJS
// it('should validate Blob', function () {
// 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);
});
});
+27
View File
@@ -0,0 +1,27 @@
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);
});
});
+12
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');
});
});