From ae248812d8e87afd0a50661b6d2e82060d22f6cb Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Tue, 5 Apr 2016 13:20:53 -0700 Subject: [PATCH] allow no callback for detect, some and family. Fixes #1096 --- lib/internal/createTester.js | 3 +++ mocha_test/detect.js | 14 ++++++++++++++ mocha_test/some.js | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/lib/internal/createTester.js b/lib/internal/createTester.js index 662f5e893..ac38bf75b 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 77c68c5af..9c9d06c64 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 d2c6e7757..9e7cef02b 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);