diff --git a/lib/assert.js b/lib/assert.js index 64b02edb570809..3bd627a20a639e 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -47,7 +47,7 @@ const assert = module.exports = ok; // TODO(jasnell): Consider moving AssertionError into internal/errors.js class AssertionError extends Error { - constructor(options = {}) { + constructor(options) { if (typeof options !== 'object' || options === null) { // Lazy because the errors module itself uses assertions, leading to // a circular dependency. This can be eliminated by moving this class diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 639439bca591f2..7e264fcad2535d 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -701,12 +701,16 @@ assert.throws(() => { code: 'ERR_ASSERTION', message: new RegExp(`^'${'A'.repeat(127)} === ''$`)})); -[1, true, false, '', null, Infinity, Symbol('test')].forEach((input) => { - assert.throws( - () => new assert.AssertionError(input), - common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: /^The "options" argument must be of type object$/ - })); -}); +{ + // bad args to AssertionError constructor should throw TypeError + const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined]; + args.forEach((input) => { + assert.throws( + () => new assert.AssertionError(input), + common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: /^The "options" argument must be of type object$/ + })); + }); +}