Skip to content

Commit f6247a9

Browse files
committed
assert: restore TypeError if no arguments
In Node 7.x, calling `throw new assert.AssertionError()` resulted in a TypeError. In current master, the same call does not result in an error but, due to the default option, it results in uninformative output ("undefined undefined undefined"). This change removes the default argument, restoring a TypeError if there is no argument. This also will restore our test coverage to 100%. (The default argument is not tested in our current test suite.) PR-URL: #12843 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ea1b8a5 commit f6247a9

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lib/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const assert = module.exports = ok;
4747

4848
// TODO(jasnell): Consider moving AssertionError into internal/errors.js
4949
class AssertionError extends Error {
50-
constructor(options = {}) {
50+
constructor(options) {
5151
if (typeof options !== 'object' || options === null) {
5252
// Lazy because the errors module itself uses assertions, leading to
5353
// a circular dependency. This can be eliminated by moving this class

test/parallel/test-assert.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,16 @@ assert.throws(() => {
707707
code: 'ERR_ASSERTION',
708708
message: new RegExp(`^'${'A'.repeat(127)} === ''$`)}));
709709

710-
[1, true, false, '', null, Infinity, Symbol('test')].forEach((input) => {
711-
assert.throws(
712-
() => new assert.AssertionError(input),
713-
common.expectsError({
714-
code: 'ERR_INVALID_ARG_TYPE',
715-
type: TypeError,
716-
message: /^The "options" argument must be of type object$/
717-
}));
718-
});
710+
{
711+
// bad args to AssertionError constructor should throw TypeError
712+
const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined];
713+
args.forEach((input) => {
714+
assert.throws(
715+
() => new assert.AssertionError(input),
716+
common.expectsError({
717+
code: 'ERR_INVALID_ARG_TYPE',
718+
type: TypeError,
719+
message: /^The "options" argument must be of type object$/
720+
}));
721+
});
722+
}

0 commit comments

Comments
 (0)