mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Clarify exit early behavior in _.every doc and refine related test.
This commit is contained in:
committed by
John-David Dalton
parent
1ad55ec263
commit
6dec9cb831
@@ -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 _
|
||||
|
||||
30
test/test.js
30
test/test.js
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user