diff options
author | Alexander Early <alexander.early@gmail.com> | 2015-06-02 13:47:08 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2015-06-02 13:47:08 -0700 |
commit | 3b4fd6465afee1eaf62ec5a187ce7436f83e8b8e (patch) | |
tree | 4b3d32ce185c09cac3f1a1199f3f71992be05ae5 | |
parent | ba7c7ba719d48c910879998be0900f5d210ce746 (diff) | |
parent | 63948a81dd6196227af3f382575982f89b5cf7d8 (diff) | |
download | async-3b4fd6465afee1eaf62ec5a187ce7436f83e8b8e.tar.gz |
Merge pull request #777 from YouPers/fix775
fix(each): each with empty array that has other property never calls final callback. Closes #775
-rw-r--r-- | lib/async.js | 2 | ||||
-rwxr-xr-x | test/test-async.js | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/async.js b/lib/async.js index 629b2a5..bfc8bdd 100644 --- a/lib/async.js +++ b/lib/async.js @@ -221,7 +221,7 @@ async.eachOf = function (object, iterator, callback) { callback = _once(callback || noop); object = object || []; - var size = object.length || _keys(object).length; + var size = _isArrayLike(object) ? object.length : _keys(object).length; var completed = 0; if (!size) { return callback(null); diff --git a/test/test-async.js b/test/test-async.js index fa4f6c4..88fa9ae 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -1375,6 +1375,22 @@ exports['each empty array'] = function(test){ setTimeout(test.done, 25); }; + +exports['each empty array, with other property on the array'] = function(test){ + test.expect(1); + var myArray = []; + myArray.myProp = "anything"; + async.each(myArray, function(x, callback){ + test.ok(false, 'iterator should not be called'); + callback(); + }, function(err){ + if (err) throw err; + test.ok(true, 'should call callback'); + }); + setTimeout(test.done, 25); +}; + + exports['each error'] = function(test){ test.expect(1); async.each([1,2,3], function(x, callback){ |