Skip to content

Commit 645a97a

Browse files
BridgeARMylesBorins
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). PR-URL: #20311 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 7d9f1f3 commit 645a97a

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
@@ -708,6 +708,11 @@ exports.expectsError = function expectsError(fn, settings, exact) {
708708
}
709709

710710
function innerFn(error) {
711+
if (arguments.length !== 1) {
712+
// Do not use `assert.strictEqual()` to prevent `util.inspect` from
713+
// always being called.
714+
assert.fail(`Expected one argument, got ${util.inspect(arguments)}`);
715+
}
711716
const descriptor = Object.getOwnPropertyDescriptor(error, 'message');
712717
assert.strictEqual(descriptor.enumerable,
713718
false, 'The error message should be non-enumerable');

0 commit comments

Comments
 (0)