mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Add _.conj and _.disj test for early exits.
This commit is contained in:
21
test/test.js
21
test/test.js
@@ -2544,10 +2544,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should return `false` as soon as a predicate returns falsey', function(assert) {
|
QUnit.test('should return `false` as soon as a predicate returns falsey', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(2);
|
||||||
|
|
||||||
|
var count = 0,
|
||||||
|
falsey = function() { count++; return false; },
|
||||||
|
truthy = function() { count++; return true; },
|
||||||
|
conjed = _.conj(truthy, falsey, truthy);
|
||||||
|
|
||||||
var conjed = _.conj(_.constant(true), _.constant(null), _.constant(true));
|
|
||||||
assert.strictEqual(conjed(), false);
|
assert.strictEqual(conjed(), false);
|
||||||
|
assert.strictEqual(count, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
|
QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
|
||||||
@@ -3849,6 +3854,18 @@
|
|||||||
assert.strictEqual(disjed(), true);
|
assert.strictEqual(disjed(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
|
||||||
|
assert.expect(2);
|
||||||
|
|
||||||
|
var count = 0,
|
||||||
|
falsey = function() { count++; return false; },
|
||||||
|
truthy = function() { count++; return true; },
|
||||||
|
disjed = _.disj(falsey, truthy, falsey);
|
||||||
|
|
||||||
|
assert.strictEqual(disjed(), true);
|
||||||
|
assert.strictEqual(count, 2);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should return `false` if all predicates return falsey', function(assert) {
|
QUnit.test('should return `false` if all predicates return falsey', function(assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user