mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Add array-like tests for "Collections" methods.
This commit is contained in:
49
test/test.js
49
test/test.js
@@ -2785,15 +2785,20 @@
|
||||
|
||||
(function() {
|
||||
var methods = [
|
||||
'countBy',
|
||||
'every',
|
||||
'filter',
|
||||
'forEach',
|
||||
'forEachRight',
|
||||
'forIn',
|
||||
'forInRight',
|
||||
'forOwn',
|
||||
'forOwnRight',
|
||||
'groupBy',
|
||||
'indexBy',
|
||||
'map',
|
||||
'max',
|
||||
'min',
|
||||
'partition',
|
||||
'reject',
|
||||
'some'
|
||||
];
|
||||
@@ -2803,6 +2808,26 @@
|
||||
'some'
|
||||
];
|
||||
|
||||
var collectionMethods = [
|
||||
'countBy',
|
||||
'every',
|
||||
'filter',
|
||||
'find',
|
||||
'findLast',
|
||||
'forEach',
|
||||
'forEachRight',
|
||||
'groupBy',
|
||||
'indexBy',
|
||||
'map',
|
||||
'max',
|
||||
'min',
|
||||
'partition',
|
||||
'reduce',
|
||||
'reduceRight',
|
||||
'reject',
|
||||
'some'
|
||||
];
|
||||
|
||||
var forInMethods = [
|
||||
'forIn',
|
||||
'forInRight'
|
||||
@@ -2914,6 +2939,28 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
_.forEach(collectionMethods, function(methodName) {
|
||||
var func = _[methodName];
|
||||
|
||||
test('`_.' + methodName + '` should treat objects with lengths of `0` as array-like', 1, function() {
|
||||
var pass = true;
|
||||
func({ 'length': 0 }, function() { pass = false; }, 0);
|
||||
ok(pass);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should not treat objects with negative lengths as array-like', 1, function() {
|
||||
var pass = false;
|
||||
func({ 'length': -1 }, function() { pass = true; }, 0);
|
||||
ok(pass);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should not treat objects with non-number lengths as array-like', 1, function() {
|
||||
var pass = false;
|
||||
func({ 'length': '0' }, function() { pass = true; }, 0);
|
||||
ok(pass);
|
||||
});
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user