Add array-like tests for "Collections" methods.

This commit is contained in:
John-David Dalton
2014-03-15 02:23:43 -07:00
parent 0a2dd2a330
commit 95976814f5

View File

@@ -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);
});
});
}());
/*--------------------------------------------------------------------------*/