diff --git a/lib/assert.js b/lib/assert.js index ffa71bfad8d412..dece9a08a78142 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -92,9 +92,10 @@ function innerFail(obj) { function fail(actual, expected, message, operator, stackStartFn) { const argsLen = arguments.length; - let internalMessage; - if (argsLen === 0) { - internalMessage = 'Failed'; + let internalMessage = false; + if (actual == null && argsLen <= 1) { + internalMessage = true; + message = 'Failed'; } else if (argsLen === 1) { message = actual; actual = undefined; @@ -118,14 +119,11 @@ function fail(actual, expected, message, operator, stackStartFn) { actual, expected, operator: operator === undefined ? 'fail' : operator, - stackStartFn: stackStartFn || fail + stackStartFn: stackStartFn || fail, + message }; - if (message !== undefined) { - errArgs.message = message; - } const err = new AssertionError(errArgs); if (internalMessage) { - err.message = internalMessage; err.generatedMessage = true; } throw err; diff --git a/test/parallel/test-assert-fail.js b/test/parallel/test-assert-fail.js index 51c69372dd8e5d..e2003f2ce91da8 100644 --- a/test/parallel/test-assert-fail.js +++ b/test/parallel/test-assert-fail.js @@ -13,7 +13,8 @@ assert.throws( operator: 'fail', actual: undefined, expected: undefined, - generatedMessage: true + generatedMessage: true, + stack: /Failed/ } );