Skip to content

Commit

Permalink
Add a two-part tests for chaining, plus lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Jul 6, 2013
1 parent e00d4db commit 3a6b32f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions test/chaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ $(document).ready(function() {
hash[l]++;
return hash;
}, {}).value();
ok(counts['a'] == 16 && counts['e'] == 10, 'counted all the letters in the song');
ok(counts.a == 16 && counts.e == 10, 'counted all the letters in the song');
});

test("select/reject/sortBy", function() {
var numbers = [1,2,3,4,5,6,7,8,9,10];
numbers = _(numbers).chain().select(function(n) {
return n % 2 == 0;
return n % 2 === 0;
}).reject(function(n) {
return n % 4 == 0;
return n % 4 === 0;
}).sortBy(function(n) {
return -n;
}).value();
Expand All @@ -35,9 +35,9 @@ $(document).ready(function() {
test("select/reject/sortBy in functional style", function() {
var numbers = [1,2,3,4,5,6,7,8,9,10];
numbers = _.chain(numbers).select(function(n) {
return n % 2 == 0;
return n % 2 === 0;
}).reject(function(n) {
return n % 4 == 0;
return n % 4 === 0;
}).sortBy(function(n) {
return -n;
}).value();
Expand All @@ -56,4 +56,10 @@ $(document).ready(function() {
equal(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.');
});

test("chaining works in small stages", function() {
var o = _([1, 2, 3, 4]).chain();
deepEqual(o.filter(function(i) { return i < 3; }).value(), [1, 2]);
deepEqual(o.filter(function(i) { return i > 2; }).value(), [3, 4]);
});

});

0 comments on commit 3a6b32f

Please sign in to comment.