Skip to content

Commit

Permalink
Merge pull request jashkenas#617 from michaelficarra/patch-3
Browse files Browse the repository at this point in the history
Add tests for `_.find`.
  • Loading branch information
braddunbar committed May 26, 2012
2 parents 7ef6b6d + 6eb19ac commit 99d1023
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ $(document).ready(function() {
raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
});

test('collections: find', function() {
var array = [1, 2, 3, 4];
strictEqual(_.find(array, function(n) { return n > 2; }), 3, 'should return first found `value`');
strictEqual(_.find(array, function() { return false; }), void 0, 'should return `undefined` if `value` is not found');
});

test('collections: detect', function() {
var result = _.detect([1, 2, 3], function(num){ return num * 2 == 4; });
equal(result, 2, 'found the first "2" and broke the loop');
Expand Down

0 comments on commit 99d1023

Please sign in to comment.