Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only call callback with two args if return is undefined #11

Merged
merged 1 commit into from
May 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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