mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Moving utility functions into utils
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
var forEach = require('../../../lib/utils').forEach;
|
||||
|
||||
module.exports = {
|
||||
testArray: function (test) {
|
||||
var sum = 0;
|
||||
|
||||
forEach([1, 2, 3, 4, 5], function (val) {
|
||||
sum += val;
|
||||
});
|
||||
|
||||
test.equal(sum, 15);
|
||||
test.done();
|
||||
},
|
||||
|
||||
testObject: function (test) {
|
||||
var keys = '';
|
||||
var vals = 0;
|
||||
var obj = {
|
||||
b: 1,
|
||||
a: 2,
|
||||
r: 3
|
||||
};
|
||||
|
||||
forEach(obj, function (v, k) {
|
||||
keys += k;
|
||||
vals += v;
|
||||
});
|
||||
|
||||
test.equal(keys, 'bar');
|
||||
test.equal(vals, 6);
|
||||
test.done();
|
||||
},
|
||||
|
||||
testUndefined: function (test) {
|
||||
var count = 0;
|
||||
|
||||
forEach(undefined, function () {
|
||||
count++;
|
||||
});
|
||||
|
||||
test.equals(count, 0);
|
||||
test.done();
|
||||
},
|
||||
|
||||
testFunction: function (test) {
|
||||
var count = 0;
|
||||
|
||||
forEach(function () {}, function () {
|
||||
count++;
|
||||
})
|
||||
|
||||
test.equals(count, 1);
|
||||
test.done();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
var utils = require('../../../lib/utils');
|
||||
|
||||
module.exports = {
|
||||
testIsArray: function (test) {
|
||||
test.equals(utils.isArray([]), true);
|
||||
test.equals(utils.isArray({length: 5}), false);
|
||||
test.done();
|
||||
},
|
||||
|
||||
testIsObject: function (test) {
|
||||
test.equals(utils.isObject({}), true);
|
||||
test.equals(utils.isObject(null), false);
|
||||
test.done();
|
||||
},
|
||||
|
||||
testIsDate: function (test) {
|
||||
test.equals(utils.isDate(new Date()), true);
|
||||
test.equals(utils.isDate(Date.now()), false);
|
||||
test.done();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
var merge = require('../../../lib/utils').merge;
|
||||
|
||||
module.exports = {
|
||||
testImmutability: function (test) {
|
||||
var a = {};
|
||||
var b = {foo: 123};
|
||||
var c = {bar: 456};
|
||||
|
||||
merge(a, b, c);
|
||||
|
||||
test.equals(typeof a.foo, 'undefined');
|
||||
test.equals(typeof a.bar, 'undefined');
|
||||
test.equals(typeof b.bar, 'undefined');
|
||||
test.equals(typeof c.foo, 'undefined');
|
||||
test.done();
|
||||
},
|
||||
|
||||
testMerge: function (test) {
|
||||
var a = {foo: 123};
|
||||
var b = {bar: 456};
|
||||
var c = {foo: 789};
|
||||
var d = merge(a, b, c);
|
||||
|
||||
test.equals(d.foo, 789);
|
||||
test.equals(d.bar, 456);
|
||||
test.done();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
var trim = require('../../../lib/utils').trim;
|
||||
|
||||
module.exports = {
|
||||
testTrim: function (test) {
|
||||
test.equals(trim(' foo '), 'foo');
|
||||
test.done();
|
||||
},
|
||||
|
||||
testTrimTab: function (test) {
|
||||
test.equals(trim('\tfoo'), 'foo');
|
||||
test.done();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user