Skip to content

Commit

Permalink
Merge pull request #11 from tschaub/preserve-arity
Browse files Browse the repository at this point in the history
Only call callback with two args if return is undefined.
  • Loading branch information
tschaub committed May 16, 2014
2 parents 456da43 + a8f9361 commit 7aad898
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ function maybeCallback(callback, thisArg, func) {
err = e;
}
process.nextTick(function() {
callback(err, val);
if (val === undefined) {
callback(err);
} else {
callback(err, val);
}
});
} else {
return func.call(thisArg);
Expand Down
14 changes: 14 additions & 0 deletions test/lib/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,20 @@ describe('Mocking the file system', function() {
});
});

it('calls callback with a single argument on success', function(done) {
fs.mkdir('parent/arity', function(err) {
assert.equal(arguments.length, 1);
done();
});
});

it('calls callback with a single argument on failure', function(done) {
fs.mkdir('parent', function(err) {
assert.instanceOf(err, Error);
done();
});
});

});

describe('fs.mkdirSync(path, [mode])', function() {
Expand Down

0 comments on commit 7aad898

Please sign in to comment.