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: https://github.com/nodejs/node/pull/12843 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
ea1b8a5cbc
commit
f6247a945c
@ -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
|
||||
|
@ -707,7 +707,10 @@ assert.throws(() => {
|
||||
code: 'ERR_ASSERTION',
|
||||
message: new RegExp(`^'${'A'.repeat(127)} === ''$`)}));
|
||||
|
||||
[1, true, false, '', null, Infinity, Symbol('test')].forEach((input) => {
|
||||
{
|
||||
// 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({
|
||||
@ -715,4 +718,5 @@ assert.throws(() => {
|
||||
type: TypeError,
|
||||
message: /^The "options" argument must be of type object$/
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user