Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added test for issue 10, make sure series and parallel return origina…

…l falsy values instead of null
  • Loading branch information...
commit 74b9dc2a6c149daa6ca09f63e327f2da8eafd329 1 parent a3f2a20
Caolan McMahon authored January 18, 2011
4  lib/async.js
@@ -423,7 +423,7 @@
423 423
                         if (args.length <= 1) {
424 424
                             args = args[0];
425 425
                         }
426  
-                        callback.call(null, err, args || null);
  426
+                        callback.call(null, err, args);
427 427
                     });
428 428
                 }
429 429
             }, callback);
@@ -455,7 +455,7 @@
455 455
                         if (args.length <= 1) {
456 456
                             args = args[0];
457 457
                         }
458  
-                        callback.call(null, err, args || null);
  458
+                        callback.call(null, err, args);
459 459
                     });
460 460
                 }
461 461
             }, callback);
70  test/test-async.js
@@ -1271,3 +1271,73 @@ exports['memoize custom hash function'] = function (test) {
1271 1271
     });
1272 1272
     test.done();
1273 1273
 };
  1274
+
  1275
+// Issue 10 on github: https://github.com/caolan/async/issues#issue/10
  1276
+exports['falsy return values in series'] = function (test) {
  1277
+    function taskFalse(callback) {
  1278
+        process.nextTick(function() {
  1279
+            callback(null, false);
  1280
+        });
  1281
+    };
  1282
+    function taskUndefined(callback) {
  1283
+        process.nextTick(function() {
  1284
+            callback(null, undefined);
  1285
+        });
  1286
+    };
  1287
+    function taskEmpty(callback) {
  1288
+        process.nextTick(function() {
  1289
+            callback(null);
  1290
+        });
  1291
+    };
  1292
+    function taskNull(callback) {
  1293
+        process.nextTick(function() {
  1294
+            callback(null, null);
  1295
+        });
  1296
+    };
  1297
+    async.series(
  1298
+        [taskFalse, taskUndefined, taskEmpty, taskNull],
  1299
+        function(err, results) {
  1300
+            test.same(results, [false, undefined, undefined, null]);
  1301
+            test.strictEqual(results[0], false);
  1302
+            test.strictEqual(results[1], undefined);
  1303
+            test.strictEqual(results[2], undefined);
  1304
+            test.strictEqual(results[3], null);
  1305
+            test.done();
  1306
+        }
  1307
+    );
  1308
+};
  1309
+
  1310
+// Issue 10 on github: https://github.com/caolan/async/issues#issue/10
  1311
+exports['falsy return values in parallel'] = function (test) {
  1312
+    function taskFalse(callback) {
  1313
+        process.nextTick(function() {
  1314
+            callback(null, false);
  1315
+        });
  1316
+    };
  1317
+    function taskUndefined(callback) {
  1318
+        process.nextTick(function() {
  1319
+            callback(null, undefined);
  1320
+        });
  1321
+    };
  1322
+    function taskEmpty(callback) {
  1323
+        process.nextTick(function() {
  1324
+            callback(null);
  1325
+        });
  1326
+    };
  1327
+    function taskNull(callback) {
  1328
+        process.nextTick(function() {
  1329
+            callback(null, null);
  1330
+        });
  1331
+    };
  1332
+    async.parallel(
  1333
+        [taskFalse, taskUndefined, taskEmpty, taskNull],
  1334
+        function(err, results) {
  1335
+            test.same(results, [false, undefined, undefined, null]);
  1336
+            test.strictEqual(results[0], false);
  1337
+            test.strictEqual(results[1], undefined);
  1338
+            test.strictEqual(results[2], undefined);
  1339
+            test.strictEqual(results[3], null);
  1340
+            test.done();
  1341
+        }
  1342
+    );
  1343
+};

0 notes on commit 74b9dc2

Please sign in to comment.
Something went wrong with that request. Please try again.