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).

Backport-PR-URL: #22850
PR-URL: #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 BethGriggs committed Oct 16, 2018
1 parent 28a6e59 commit aa341d1
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 aa341d1

Please sign in to comment.