diff options
author | Mark Yen <mark@uber.com> | 2015-07-28 14:25:39 -0700 |
---|---|---|
committer | Mark Yen <mark@uber.com> | 2015-07-28 14:25:39 -0700 |
commit | f353d7ab30e27d22f2e1cd60c8e39cdedbb2d4c7 (patch) | |
tree | 68ead9fba21e84cfe1a307e1de32663770e13909 /test | |
parent | 1f97538586e09ce76168fa1ceb04288fd958b0a0 (diff) | |
download | async-f353d7ab30e27d22f2e1cd60c8e39cdedbb2d4c7.tar.gz |
Add detectLimit
Diffstat (limited to 'test')
-rwxr-xr-x | test/test-async.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/test-async.js b/test/test-async.js index dc7d949..18894b0 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -2329,6 +2329,43 @@ exports['detectSeries - ensure stop'] = function (test) { }); }; +exports['detectLimit'] = function(test){ + test.expect(2); + var call_order = []; + async.detectLimit([3, 2, 1], 2, detectIterator.bind(this, call_order), function(result) { + call_order.push('callback'); + test.equals(result, 2); + }); + setTimeout(function() { + test.same(call_order, [2, 'callback', 3]); + test.done(); + }, 100); +}; + +exports['detectLimit - multiple matches'] = function(test){ + test.expect(2); + var call_order = []; + async.detectLimit([3,2,2,1,2], 2, detectIterator.bind(this, call_order), function(result){ + call_order.push('callback'); + test.equals(result, 2); + }); + setTimeout(function(){ + test.same(call_order, [2, 'callback', 3]); + test.done(); + }, 100); +}; + +exports['detectLimit - ensure stop'] = function (test) { + test.expect(1); + async.detectLimit([1, 2, 3, 4, 5], 2, function (num, cb) { + if (num > 4) throw new Error("detectLimit did not stop iterating"); + cb(num === 3); + }, function (result) { + test.equals(result, 3); + test.done(); + }); +}; + exports['sortBy'] = function(test){ test.expect(2); |