mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Add unit tests to check "Collections" methods return values.
Former-commit-id: 6ac6cd97414035f74a102a51e913099e744d9a93
This commit is contained in:
22
test/test.js
22
test/test.js
@@ -1727,6 +1727,17 @@
|
||||
|
||||
(function() {
|
||||
test('should allow falsey arguments', function() {
|
||||
var returnArrays = [
|
||||
'filter',
|
||||
'invoke',
|
||||
'map',
|
||||
'pluck',
|
||||
'reject',
|
||||
'sortBy',
|
||||
'toArray',
|
||||
'where'
|
||||
];
|
||||
|
||||
var funcs = _.without.apply(_, [_.functions(_)].concat([
|
||||
'_',
|
||||
'_iteratorTemplate',
|
||||
@@ -1748,17 +1759,24 @@
|
||||
]));
|
||||
|
||||
_.each(funcs, function(methodName) {
|
||||
var func = _[methodName],
|
||||
var actual = [],
|
||||
expected = _.times(falsey.length, function() { return []; }),
|
||||
func = _[methodName],
|
||||
pass = true;
|
||||
|
||||
_.each(falsey, function(value, index) {
|
||||
try {
|
||||
index ? func(value) : func();
|
||||
actual.push(index ? func(value) : func());
|
||||
} catch(e) {
|
||||
pass = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (_.indexOf(returnArrays, methodName) > -1) {
|
||||
deepEqual(actual, expected, '_.' + methodName + ' returns an array');
|
||||
} else {
|
||||
skipTest(falsey.length);
|
||||
}
|
||||
ok(pass, '_.' + methodName + ' allows falsey arguments');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user