Clarify exit early behavior in _.every doc and refine related test.

This commit is contained in:
Miro Mannino
2015-10-12 13:46:06 +04:00
committed by John-David Dalton
parent 1ad55ec263
commit 6dec9cb831
2 changed files with 24 additions and 9 deletions

View File

@@ -6739,7 +6739,8 @@
/**
* Checks if `predicate` returns truthy for **all** elements of `collection`.
* The predicate is invoked with three arguments: (value, index|key, collection).
* Iteration is stopped once `predicate` returns falsey. The predicate is
* invoked with three arguments: (value, index|key, collection).
*
* @static
* @memberOf _

View File

@@ -4453,9 +4453,16 @@
});
QUnit.test('should return `false` as soon as `predicate` returns falsey', function(assert) {
assert.expect(1);
assert.expect(2);
assert.strictEqual(_.every([true, null, true], _.identity), false);
var count = 0;
assert.strictEqual(_.every([true, null, true], function(value) {
count++;
return value;
}), false);
assert.strictEqual(count, 2);
});
QUnit.test('should work with collections of `undefined` values (test in IE < 9)', function(assert) {
@@ -16928,6 +16935,19 @@
assert.deepEqual(actual, expected);
});
QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
assert.expect(2);
var count = 0;
assert.strictEqual(_.some([null, true, null], function(value) {
count++;
return value;
}), true);
assert.strictEqual(count, 2);
});
QUnit.test('should return `false` if `predicate` returns falsey for all elements', function(assert) {
assert.expect(2);
@@ -16935,12 +16955,6 @@
assert.strictEqual(_.some([null, 0, ''], _.identity), false);
});
QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
assert.expect(1);
assert.strictEqual(_.some([null, true, null], _.identity), true);
});
QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
assert.expect(2);