diff options
author | indexzero <charlie.robbins@gmail.com> | 2011-06-12 19:39:41 -0400 |
---|---|---|
committer | indexzero <charlie.robbins@gmail.com> | 2011-06-12 19:39:41 -0400 |
commit | 90c80a15f3f49bfa75880a6c724d4aceccb9ea4a (patch) | |
tree | 39b4aedf7f13884acf0cfc99448c31bfab5563ab /test/test-async.js | |
parent | cbb0a422a91e7150428593f12686b7354dce2b7a (diff) | |
download | async-90c80a15f3f49bfa75880a6c724d4aceccb9ea4a.tar.gz |
[api test] Added `async.forEachLimit()` and associated tests
Diffstat (limited to 'test/test-async.js')
-rw-r--r-- | test/test-async.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/test-async.js b/test/test-async.js index 4a7f986..a00866a 100644 --- a/test/test-async.js +++ b/test/test-async.js @@ -491,6 +491,59 @@ exports['forEachSeries error'] = function(test){ setTimeout(test.done, 50); }; +exports['forEachLimit'] = function(test){ + var args = []; + var arr = [0,1,2,3,4,5,6,7,8,9]; + async.forEachLimit(arr, 2, function(x,callback){ + setTimeout(function(){ + args.push(x); + callback(); + }, x*5); + }, function(err){ + test.same(args, arr); + test.done(); + }); +}; + +exports['forEachLimit empty array'] = function(test){ + test.expect(1); + async.forEachLimit([], 2, function(x, callback){ + test.ok(false, 'iterator should not be called'); + callback(); + }, function(err){ + test.ok(true, 'should call callback'); + }); + setTimeout(test.done, 25); +}; + +exports['forEachLimit zero limit'] = function(test){ + test.expect(1); + async.forEachLimit([0,1,2,3,4,5], 0, function(x, callback){ + test.ok(false, 'iterator should not be called'); + callback(); + }, function(err){ + test.ok(true, 'should call callback'); + }); + setTimeout(test.done, 25); +}; + +exports['forEachLimit error'] = function(test){ + test.expect(2); + var arr = [0,1,2,3,4,5,6,7,8,9]; + var call_order = []; + + async.forEachLimit(arr, 3, function(x, callback){ + call_order.push(x); + if (x === 2) { + callback('error'); + } + }, function(err){ + test.same(call_order, [0,1,2]); + test.equals(err, 'error'); + }); + setTimeout(test.done, 25); +}; + exports['map'] = function(test){ var call_order = []; async.map([1,3,2], function(x, callback){ |