mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Added _.defaultTo. (#2381)
This commit is contained in:
committed by
John-David Dalton
parent
e582ad226a
commit
5fbc5303ff
@@ -833,6 +833,42 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('fp.defaultTo');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should return a default value if input is undefined', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
// default (inverse params)
|
||||
var actual = fp.defaultTo(0, fp.find(function(a) { return a > 1; }, [1,2,3]));
|
||||
assert.deepEqual(actual, 2);
|
||||
|
||||
var actual = fp.defaultTo(0, fp.find(function(a) { return a > 5; }, [1,2,3]));
|
||||
assert.deepEqual(actual, 0);
|
||||
|
||||
// curried
|
||||
var actual = fp.defaultTo(0)(fp.find(function(a) { return a > 1; })([1,2,3]));
|
||||
assert.deepEqual(actual, 2);
|
||||
|
||||
var actual = fp.defaultTo(0)(fp.find(function(a) { return a > 5; })([1,2,3]));
|
||||
assert.deepEqual(actual, 0);
|
||||
});
|
||||
|
||||
QUnit.test('should work in a flow', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var actual = fp.flow([
|
||||
fp.find(function(a) { return a > 3 }),
|
||||
fp.defaultTo(0)
|
||||
]);
|
||||
|
||||
assert.deepEqual(actual([1,2,3]), 0);
|
||||
assert.deepEqual(actual([3,4,5]), 4);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('fp.difference');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user