Permalink
Browse files

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

…l falsy values instead of null
  • Loading branch information...
1 parent a3f2a20 commit 74b9dc2a6c149daa6ca09f63e327f2da8eafd329 @caolan caolan committed Jan 18, 2011
Showing with 72 additions and 2 deletions.
  1. +2 −2 lib/async.js
  2. +70 −0 test/test-async.js
View
@@ -423,7 +423,7 @@
if (args.length <= 1) {
args = args[0];
}
- callback.call(null, err, args || null);
+ callback.call(null, err, args);
});
}
}, callback);
@@ -455,7 +455,7 @@
if (args.length <= 1) {
args = args[0];
}
- callback.call(null, err, args || null);
+ callback.call(null, err, args);
});
}
}, callback);
View
@@ -1271,3 +1271,73 @@ exports['memoize custom hash function'] = function (test) {
});
test.done();
};
+
+// Issue 10 on github: https://github.com/caolan/async/issues#issue/10
+exports['falsy return values in series'] = function (test) {
+ function taskFalse(callback) {
+ process.nextTick(function() {
+ callback(null, false);
+ });
+ };
+ function taskUndefined(callback) {
+ process.nextTick(function() {
+ callback(null, undefined);
+ });
+ };
+ function taskEmpty(callback) {
+ process.nextTick(function() {
+ callback(null);
+ });
+ };
+ function taskNull(callback) {
+ process.nextTick(function() {
+ callback(null, null);
+ });
+ };
+ async.series(
+ [taskFalse, taskUndefined, taskEmpty, taskNull],
+ function(err, results) {
+ test.same(results, [false, undefined, undefined, null]);
+ test.strictEqual(results[0], false);
+ test.strictEqual(results[1], undefined);
+ test.strictEqual(results[2], undefined);
+ test.strictEqual(results[3], null);
+ test.done();
+ }
+ );
+};
+
+// Issue 10 on github: https://github.com/caolan/async/issues#issue/10
+exports['falsy return values in parallel'] = function (test) {
+ function taskFalse(callback) {
+ process.nextTick(function() {
+ callback(null, false);
+ });
+ };
+ function taskUndefined(callback) {
+ process.nextTick(function() {
+ callback(null, undefined);
+ });
+ };
+ function taskEmpty(callback) {
+ process.nextTick(function() {
+ callback(null);
+ });
+ };
+ function taskNull(callback) {
+ process.nextTick(function() {
+ callback(null, null);
+ });
+ };
+ async.parallel(
+ [taskFalse, taskUndefined, taskEmpty, taskNull],
+ function(err, results) {
+ test.same(results, [false, undefined, undefined, null]);
+ test.strictEqual(results[0], false);
+ test.strictEqual(results[1], undefined);
+ test.strictEqual(results[2], undefined);
+ test.strictEqual(results[3], null);
+ test.done();
+ }
+ );
+};

0 comments on commit 74b9dc2

Please sign in to comment.