diff options
author | Alexander Early <alexander.early@gmail.com> | 2016-04-05 13:20:53 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2016-04-05 13:20:53 -0700 |
commit | ae248812d8e87afd0a50661b6d2e82060d22f6cb (patch) | |
tree | 49365c565797ac3fe721972351842260567fe741 | |
parent | e9f6f751c5a3b4f1f893ed0fc717b0b5fbf3750e (diff) | |
download | async-ae248812d8e87afd0a50661b6d2e82060d22f6cb.tar.gz |
allow no callback for detect, some and family. Fixes #1096
-rw-r--r-- | lib/internal/createTester.js | 3 | ||||
-rw-r--r-- | mocha_test/detect.js | 14 | ||||
-rw-r--r-- | mocha_test/some.js | 14 |
3 files changed, 31 insertions, 0 deletions
diff --git a/lib/internal/createTester.js b/lib/internal/createTester.js index 662f5e8..ac38bf7 100644 --- a/lib/internal/createTester.js +++ b/lib/internal/createTester.js @@ -1,4 +1,5 @@ 'use strict'; +import noop from 'lodash/noop'; export default function _createTester(eachfn, check, getResult) { return function(arr, limit, iteratee, cb) { @@ -27,9 +28,11 @@ export default function _createTester(eachfn, check, getResult) { }); } if (arguments.length > 3) { + cb = cb || noop; eachfn(arr, limit, wrappedIteratee, done); } else { cb = iteratee; + cb = cb || noop; iteratee = limit; eachfn(arr, wrappedIteratee, done); } diff --git a/mocha_test/detect.js b/mocha_test/detect.js index 77c68c5..9c9d06c 100644 --- a/mocha_test/detect.js +++ b/mocha_test/detect.js @@ -72,6 +72,20 @@ describe("detect", function () { }, 50); }); + it('detect no callback', function(done) { + var calls = []; + + async.detect([1, 2, 3], function (val, cb) { + calls.push(val); + cb(); + }); + + setTimeout(function () { + expect(calls).to.eql([1, 2, 3]); + done(); + }, 10) + }); + it('detectSeries - ensure stop', function (done) { async.detectSeries([1, 2, 3, 4, 5], function (num, cb) { if (num > 3) throw new Error("detectSeries did not stop iterating"); diff --git a/mocha_test/some.js b/mocha_test/some.js index d2c6e77..9e7cef0 100644 --- a/mocha_test/some.js +++ b/mocha_test/some.js @@ -49,6 +49,20 @@ describe("some", function () { }); }); + it('some no callback', function(done) { + var calls = []; + + async.some([1, 2, 3], function (val, cb) { + calls.push(val); + cb(); + }); + + setTimeout(function () { + expect(calls).to.eql([1, 2, 3]); + done(); + }, 10) + }); + it('someLimit true', function(done){ async.someLimit([3,1,2], 2, function(x, callback){ setTimeout(function(){callback(null, x === 2);}, 0); |