forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforEach.js
44 lines (36 loc) · 1.16 KB
/
forEach.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
var R = require('..');
var eq = require('./shared/eq');
describe('forEach', function() {
var list = [{x: 1, y: 2}, {x: 100, y: 200}, {x: 300, y: 400}, {x: 234, y: 345}];
it('performs the passed in function on each element of the list', function() {
var sideEffect = {};
R.forEach(function(elem) { sideEffect[elem.x] = elem.y; }, list);
eq(sideEffect, {1: 2, 100: 200, 300: 400, 234: 345});
});
it('returns the original list', function() {
var s = '';
eq(R.forEach(function(obj) { s += obj.x; }, list), list);
eq('1100300234', s);
});
it('handles empty list', function() {
eq(R.forEach(function(x) { return x * x; }, []), []);
});
it('dispatches to `forEach` method', function() {
var dispatched = false;
var fn = function() {};
function DummyList() {}
DummyList.prototype.forEach = function(callback) {
dispatched = true;
eq(callback, fn);
};
R.forEach(fn, new DummyList());
eq(dispatched, true);
});
it('is curried', function() {
var xStr = '';
var xe = R.forEach(function(x) { xStr += (x + ' '); });
eq(typeof xe, 'function');
xe([1, 2, 4]);
eq(xStr, '1 2 4 ');
});
});