Skip to content

Commit

Permalink
test: verify arguments length in common.expectsError
Browse files Browse the repository at this point in the history
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).

PR-URL: nodejs#20311
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
BridgeAR authored and kjin committed Sep 19, 2018
1 parent 455a48d commit f287842
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,11 @@ exports.expectsError = function expectsError(fn, settings, exact) {
fn = undefined;
}
function innerFn(error) {
if (arguments.length !== 1) {
// Do not use `assert.strictEqual()` to prevent `util.inspect` from
// always being called.
assert.fail(`Expected one argument, got ${util.inspect(arguments)}`);
}
assert.strictEqual(error.code, settings.code);
const descriptor = Object.getOwnPropertyDescriptor(error, 'message');
assert.strictEqual(descriptor.enumerable,
Expand Down

0 comments on commit f287842

Please sign in to comment.