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,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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user