mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +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() {
|
(function() {
|
||||||
var methods = [
|
var methods = [
|
||||||
|
'countBy',
|
||||||
'every',
|
'every',
|
||||||
'filter',
|
'filter',
|
||||||
'forEach',
|
|
||||||
'forEachRight',
|
'forEachRight',
|
||||||
'forIn',
|
'forIn',
|
||||||
'forInRight',
|
'forInRight',
|
||||||
'forOwn',
|
'forOwn',
|
||||||
'forOwnRight',
|
'forOwnRight',
|
||||||
|
'groupBy',
|
||||||
|
'indexBy',
|
||||||
'map',
|
'map',
|
||||||
|
'max',
|
||||||
|
'min',
|
||||||
|
'partition',
|
||||||
'reject',
|
'reject',
|
||||||
'some'
|
'some'
|
||||||
];
|
];
|
||||||
@@ -2803,6 +2808,26 @@
|
|||||||
'some'
|
'some'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var collectionMethods = [
|
||||||
|
'countBy',
|
||||||
|
'every',
|
||||||
|
'filter',
|
||||||
|
'find',
|
||||||
|
'findLast',
|
||||||
|
'forEach',
|
||||||
|
'forEachRight',
|
||||||
|
'groupBy',
|
||||||
|
'indexBy',
|
||||||
|
'map',
|
||||||
|
'max',
|
||||||
|
'min',
|
||||||
|
'partition',
|
||||||
|
'reduce',
|
||||||
|
'reduceRight',
|
||||||
|
'reject',
|
||||||
|
'some'
|
||||||
|
];
|
||||||
|
|
||||||
var forInMethods = [
|
var forInMethods = [
|
||||||
'forIn',
|
'forIn',
|
||||||
'forInRight'
|
'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