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: #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 committed Apr 29, 2018
1 parent bb546ac commit 29cddb4
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 @@ -708,6 +708,11 @@ exports.expectsError = function expectsError(fn, settings, exact) {
}

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)}`);
}
const descriptor = Object.getOwnPropertyDescriptor(error, 'message');
assert.strictEqual(descriptor.enumerable,
false, 'The error message should be non-enumerable');
Expand Down

0 comments on commit 29cddb4

Please sign in to comment.