Skip to content

Commit aa341d1

Browse files
BridgeARBethGriggs
authored andcommitted
test: verify arguments length in common.expectsError
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 <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 28a6e59 commit aa341d1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

test/common/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,11 @@ exports.expectsError = function expectsError(fn, settings, exact) {
691691
fn = undefined;
692692
}
693693
function innerFn(error) {
694+
if (arguments.length !== 1) {
695+
// Do not use `assert.strictEqual()` to prevent `util.inspect` from
696+
// always being called.
697+
assert.fail(`Expected one argument, got ${util.inspect(arguments)}`);
698+
}
694699
assert.strictEqual(error.code, settings.code);
695700
const descriptor = Object.getOwnPropertyDescriptor(error, 'message');
696701
assert.strictEqual(descriptor.enumerable,

0 commit comments

Comments
 (0)