Add tests to ensure length is computed before iteration.

This commit is contained in:
John-David Dalton
2014-08-30 16:36:53 -07:00
parent 5458b007d1
commit f248a8383b

View File

@@ -4181,6 +4181,25 @@
ok(pass);
});
});
_.each(collectionMethods.concat(objectMethods), function(methodName) {
var func = _[methodName];
test('`_.' + methodName + '` should compute length before iteration', 2, function() {
_.each([[0], { 'a': 0 }], function(collection) {
var count = 0;
func(collection, function() {
collection[++count] = count;
if (count > 1) {
return false;
}
}, 0);
strictEqual(count, 1);
});
});
});
}());
/*--------------------------------------------------------------------------*/