summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Argasinski <argasinski.hubert@gmail.com>2019-02-27 21:47:37 -0600
committerHubert Argasinski <argasinski.hubert@gmail.com>2019-02-27 21:47:37 -0600
commit4c2bd0299f6b9b02526a71415c8628b71922500a (patch)
treee4798a8328e4203b0056f5ab853ede7d0b743214
parentce0a7e203e8d3b2a68ca674038dad86e1a221e00 (diff)
downloadasync-whilst-first-it-fix.tar.gz
initialize results in whilst [fixes #1626]whilst-first-it-fix
-rw-r--r--lib/whilst.js2
-rw-r--r--test/whilst.js18
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/whilst.js b/lib/whilst.js
index 1013d37..361b72d 100644
--- a/lib/whilst.js
+++ b/lib/whilst.js
@@ -40,7 +40,7 @@ function whilst(test, iteratee, callback) {
callback = onlyOnce(callback);
var _fn = wrapAsync(iteratee);
var _test = wrapAsync(test);
- var results
+ var results = [];
function next(err, ...rest) {
if (err) return callback(err);
diff --git a/test/whilst.js b/test/whilst.js
index 1c222c9..1ee6f11 100644
--- a/test/whilst.js
+++ b/test/whilst.js
@@ -64,6 +64,24 @@ describe('whilst', () => {
}, 10)
});
+ it('should not error when test is false on first iteration', (done) => {
+ var counter = 0;
+
+ async.whilst(
+ (cb) => cb(null, false),
+ (cb) => {
+ counter++;
+ cb(null);
+ },
+ (err, result) => {
+ expect(err).to.eql(null);
+ expect(result).to.be.undefined;
+ expect(counter).to.equal(0);
+ done();
+ }
+ );
+ });
+
it('doWhilst', (done) => {
var call_order = [];