From f248a8383b049d8a19bc4854d30563960bdd39a6 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 30 Aug 2014 16:36:53 -0700 Subject: [PATCH] Add tests to ensure length is computed before iteration. --- test/test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test.js b/test/test.js index 767e80ae4..a59029fa8 100644 --- a/test/test.js +++ b/test/test.js @@ -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); + }); + }); + }); }()); /*--------------------------------------------------------------------------*/