diff --git a/lib/assert.js b/lib/assert.js index 5e69e17515d..385ec332a6f 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -510,7 +510,8 @@ function expectsNoError(stackStartFn, actual, error, message) { actual, expected: error, operator: stackStartFn.name, - message: `Got unwanted ${fnType}${details}\n${actual && actual.message}`, + message: `Got unwanted ${fnType}${details}\n` + + `Actual message: "${actual && actual.message}"`, stackStartFn }); } diff --git a/test/parallel/test-assert-async.js b/test/parallel/test-assert-async.js index b6b744c9b1e..cc557d504ac 100644 --- a/test/parallel/test-assert-async.js +++ b/test/parallel/test-assert-async.js @@ -34,7 +34,8 @@ common.crashOnUnhandledRejection(); assert(err instanceof assert.AssertionError, `${err.name} is not instance of AssertionError`); assert.strictEqual(err.code, 'ERR_ASSERTION'); - assert(/^Got unwanted rejection\.\n$/.test(err.message)); + assert.strictEqual(err.message, + 'Got unwanted rejection.\nActual message: ""'); assert.strictEqual(err.operator, 'doesNotReject'); assert.ok(!err.stack.includes('at Function.doesNotReject')); return true; diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 66851fa5ea7..4115167d4b4 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -124,29 +124,22 @@ assert.throws(() => thrower(TypeError)); assert.ok(threw, 'a.doesNotThrow is not catching type matching errors'); } -common.expectsError( +assert.throws( () => a.doesNotThrow(() => thrower(Error), 'user message'), { - type: a.AssertionError, + name: 'AssertionError [ERR_ASSERTION]', code: 'ERR_ASSERTION', operator: 'doesNotThrow', - message: 'Got unwanted exception: user message\n[object Object]' + message: 'Got unwanted exception: user message\n' + + 'Actual message: "[object Object]"' } ); -common.expectsError( - () => a.doesNotThrow(() => thrower(Error), 'user message'), - { - code: 'ERR_ASSERTION', - message: /Got unwanted exception: user message\n\[object Object\]/ - } -); - -common.expectsError( +assert.throws( () => a.doesNotThrow(() => thrower(Error)), { code: 'ERR_ASSERTION', - message: /Got unwanted exception\.\n\[object Object\]/ + message: 'Got unwanted exception.\nActual message: "[object Object]"' } ); @@ -833,13 +826,13 @@ common.expectsError( // eslint-disable-next-line no-throw-literal assert.throws(() => { throw undefined; }, /undefined/); - common.expectsError( + assert.throws( // eslint-disable-next-line no-throw-literal () => a.doesNotThrow(() => { throw undefined; }), { - type: assert.AssertionError, + name: 'AssertionError [ERR_ASSERTION]', code: 'ERR_ASSERTION', - message: 'Got unwanted exception.\nundefined' + message: 'Got unwanted exception.\nActual message: "undefined"' } ); }