diff --git a/lib/assert.js b/lib/assert.js index 367b5287bff632..0d061dbff617f7 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -183,7 +183,7 @@ function innerThrows(shouldThrow, block, expected, message) { details += ` (${expected.name})`; } details += message ? `: ${message}` : '.'; - fail(actual, expected, `Missing expected exception${details}`, fail); + fail(actual, expected, `Missing expected exception${details}`, 'throws'); } if (expected && expectedException(actual, expected) === false) { throw actual; @@ -194,7 +194,7 @@ function innerThrows(shouldThrow, block, expected, message) { fail(actual, expected, `Got unwanted exception${details}\n${actual.message}`, - fail); + 'doesNotThrow'); } throw actual; } diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index e198ce5ae4e530..885ac0013b2a5a 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -466,10 +466,15 @@ assert.throws(() => { assert.ifError(new Error('test error')); }, assert.doesNotThrow(() => { assert.ifError(null); }); assert.doesNotThrow(() => { assert.ifError(); }); -assert.throws(() => { - assert.doesNotThrow(makeBlock(thrower, Error), 'user message'); -}, /Got unwanted exception: user message/, - 'a.doesNotThrow ignores user message'); +common.expectsError( + () => assert.doesNotThrow(makeBlock(thrower, Error), 'user message'), + { + type: a.AssertionError, + code: 'ERR_ASSERTION', + operator: 'doesNotThrow', + message: 'Got unwanted exception: user message\n[object Object]' + } +); { let threw = false; @@ -556,7 +561,8 @@ a.throws(makeBlock(thrower, TypeError), (err) => { () => { a.throws((noop)); }, common.expectsError({ code: 'ERR_ASSERTION', - message: /^Missing expected exception\.$/ + message: /^Missing expected exception\.$/, + operator: 'throws' })); assert.throws(