mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +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() {
|
(function() {
|
||||||
test('should allow falsey arguments', function() {
|
test('should allow falsey arguments', function() {
|
||||||
|
var returnArrays = [
|
||||||
|
'filter',
|
||||||
|
'invoke',
|
||||||
|
'map',
|
||||||
|
'pluck',
|
||||||
|
'reject',
|
||||||
|
'sortBy',
|
||||||
|
'toArray',
|
||||||
|
'where'
|
||||||
|
];
|
||||||
|
|
||||||
var funcs = _.without.apply(_, [_.functions(_)].concat([
|
var funcs = _.without.apply(_, [_.functions(_)].concat([
|
||||||
'_',
|
'_',
|
||||||
'_iteratorTemplate',
|
'_iteratorTemplate',
|
||||||
@@ -1748,17 +1759,24 @@
|
|||||||
]));
|
]));
|
||||||
|
|
||||||
_.each(funcs, function(methodName) {
|
_.each(funcs, function(methodName) {
|
||||||
var func = _[methodName],
|
var actual = [],
|
||||||
|
expected = _.times(falsey.length, function() { return []; }),
|
||||||
|
func = _[methodName],
|
||||||
pass = true;
|
pass = true;
|
||||||
|
|
||||||
_.each(falsey, function(value, index) {
|
_.each(falsey, function(value, index) {
|
||||||
try {
|
try {
|
||||||
index ? func(value) : func();
|
actual.push(index ? func(value) : func());
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
pass = false;
|
pass = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (_.indexOf(returnArrays, methodName) > -1) {
|
||||||
|
deepEqual(actual, expected, '_.' + methodName + ' returns an array');
|
||||||
|
} else {
|
||||||
|
skipTest(falsey.length);
|
||||||
|
}
|
||||||
ok(pass, '_.' + methodName + ' allows falsey arguments');
|
ok(pass, '_.' + methodName + ' allows falsey arguments');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user