mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Cleanup _.defaultTo.
This commit is contained in:
@@ -836,34 +836,11 @@
|
||||
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) {
|
||||
QUnit.test('should have an argument order of `defaultValue` then `value`', 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);
|
||||
assert.strictEqual(fp.defaultTo(1)(0), 0);
|
||||
assert.strictEqual(fp.defaultTo(1)(undefined), 1);
|
||||
});
|
||||
}());
|
||||
|
||||
|
||||
15
test/test.js
15
test/test.js
@@ -4604,15 +4604,18 @@
|
||||
QUnit.module('lodash.defaultTo');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should return a default value if the input is undefined', function(assert) {
|
||||
assert.expect(3);
|
||||
QUnit.test('should return a default value if `value` is `undefined`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.strictEqual(_.defaultTo(1, 0), 1);
|
||||
assert.strictEqual(_.defaultTo(undefined, 0), 0);
|
||||
var expected = lodashStable.map(falsey, function(value) {
|
||||
return value === undefined ? 1 : value;
|
||||
});
|
||||
|
||||
var actual = _.defaultTo(_.find([1,2,3], function(n) { return n > 5; }), 0);
|
||||
var actual = lodashStable.map(falsey, function(value) {
|
||||
return _.defaultTo(value, 1);
|
||||
});
|
||||
|
||||
assert.strictEqual(actual, 0);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
}());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user