-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
49 lines (43 loc) · 1.14 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*!
* array-each <https://github.com/jonschlinkert/array-each>
*
* Copyright (c) 2015, 2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var each = require('./');
describe('each', function() {
it('should return when the first arg is null', function() {
var arr;
each('', function(ele) {
arr = [ele];
});
assert.equal(arr, undefined);
});
it('should loop over each item in an array and call the given function on every element:', function() {
var res = [];
each(['a', 'b', 'c'], function(ele) {
res.push(ele + ele);
});
assert.deepEqual(res, ['aa', 'bb', 'cc']);
});
it('should "break" when `false` is returned:', function() {
var res = [];
each(['a', 'b', 'c'], function(ele, i) {
if (ele === 'b') {
return false;
}
res.push(ele + ele);
});
assert.deepEqual(res, ['aa']);
});
it('should expose the index as the second parameter:', function() {
var res = [];
each(['a', 'b', 'c'], function(ele, i) {
res.push(i);
});
assert.deepEqual(res, [0, 1, 2]);
});
});