diff options
-rw-r--r-- | mocha_test/eachOf.js | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/mocha_test/eachOf.js b/mocha_test/eachOf.js index a6c6864..dd73c22 100644 --- a/mocha_test/eachOf.js +++ b/mocha_test/eachOf.js @@ -43,6 +43,30 @@ describe("eachOf", function() { }); }); + it('forEachOf no call stack size exceed error', function(done) { + var obj = {}; + var len = 3000; + var args = new Array(len * 2); + var expected = new Array(len * 2); + + for (var i = 0; i < len; i++) { + obj["a" + i] = i; + expected[2 * i] = "a" + i; + expected[2 * i + 1] = i; + } + + async.forEachOf(obj, function(value, key, callback) { + var index = parseInt(key.slice(1), 10); + args[2 * index] = key; + args[2 * index + 1] = value; + callback(); + }, function(err) { + assert(err === null, err + " passed instead of 'null'"); + expect(args).to.eql(expected); + done(); + }); + }); + it('forEachOf - instant resolver', function(done) { var args = []; async.forEachOf({ a: 1, b: 2 }, function(x, k, cb) { @@ -139,6 +163,30 @@ describe("eachOf", function() { }); }); + it('forEachOfSeries no call stack size exceed error', function(done) { + var obj = {}; + var len = 3000; + var args = new Array(len * 2); + var expected = new Array(len * 2); + + for (var i = 0; i < len; i++) { + obj["a" + i] = i; + expected[2 * i] = "a" + i; + expected[2 * i + 1] = i; + } + + async.forEachOfSeries(obj, function(value, key, callback) { + var index = parseInt(key.slice(1), 10); + args[2 * index] = key; + args[2 * index + 1] = value; + callback(); + }, function(err) { + assert(err === null, err + " passed instead of 'null'"); + expect(args).to.eql(expected); + done(); + }); + }); + it('forEachOfSeries empty object', function(done) { async.forEachOfSeries({}, function(x, callback){ assert(false, 'iteratee should not be called'); @@ -274,7 +322,7 @@ describe("eachOf", function() { setTimeout(done, 25); }); - it('forEachOfLimit 1024 * 1024 synchronous call', function(done) { + it('forEachOfLimit no call stack size exceed error', function(done) { var count = 0; async.forEachOfLimit(_.range(1024 * 1024), Infinity, function(x, i, callback){ count++; @@ -282,8 +330,8 @@ describe("eachOf", function() { }, function(err){ if (err) throw err; expect(count).to.equal(1024 * 1024); + done(); }); - setTimeout(done, 25); }); it('forEachOfLimit error', function(done) { |