From 84948cf14fa3dd951d16fb61898e70050229223e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 9 Dec 2017 14:05:20 -0200 Subject: [PATCH] assert: fix .throws operator assert.throws and assert.doesNotThrow set the operator to a internal function. That was by accident and originally the operator was undefined. This changes it to show "throws" or "doesNotThrow". Backport-PR-URL: https://github.com/nodejs/node/pull/23223 PR-URL: https://github.com/nodejs/node/pull/17575 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Anatoli Papirovski --- lib/assert.js | 7 +++++-- test/parallel/test-assert.js | 16 +++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index b88d5a13dd29b6..ae328c4e3ac31a 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -643,7 +643,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; @@ -651,7 +651,10 @@ function innerThrows(shouldThrow, block, expected, message) { } else if (actual !== undefined) { if (!expected || expectedException(actual, expected)) { details = message ? `: ${message}` : '.'; - fail(actual, expected, `Got unwanted exception${details}`, fail); + fail(actual, + expected, + `Got unwanted exception${details}`, + 'doesNotThrow'); } throw actual; } diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 5538548a1da38a..71ee19f2e2fddb 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -463,10 +463,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]' + } +); // make sure that validating using constructor really works { @@ -525,7 +530,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(