From 085f875d79698677083b442700d9a5df87f3050b Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 9 Apr 2018 03:57:40 +0200 Subject: [PATCH 1/3] assert: provide info about actual error In case a error is caught in `assert.doesNotThrow` or `assert.doesNotReject` it will now also indicate what the real error message was. --- lib/assert.js | 3 ++- test/parallel/test-assert.js | 21 +++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 9c900fcaf32055..327ecc35627e25 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -507,7 +507,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.js b/test/parallel/test-assert.js index 54972657e94dd4..5a295886414c8c 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]' } ); @@ -839,7 +832,7 @@ common.expectsError( { type: assert.AssertionError, code: 'ERR_ASSERTION', - message: 'Got unwanted exception.\nundefined' + message: 'Got unwanted exception.\nActual message: undefined' } ); } From 7c567d3fdf3f53037ca8c7ead3d40d91084c53e6 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 9 Apr 2018 22:50:37 +0200 Subject: [PATCH 2/3] fixup: address comment --- test/parallel/test-assert.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 5a295886414c8c..a8891c980bc1af 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -826,11 +826,11 @@ 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.\nActual message: undefined' } From 3cea2597459c2df24b48bffed7840034fe07b66f Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 10 Apr 2018 03:55:19 +0200 Subject: [PATCH 3/3] fixup: fix tests and add quotes --- lib/assert.js | 2 +- test/parallel/test-assert-async.js | 3 ++- test/parallel/test-assert.js | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 327ecc35627e25..0647ad85c2b041 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -508,7 +508,7 @@ function expectsNoError(stackStartFn, actual, error, message) { expected: error, operator: stackStartFn.name, message: `Got unwanted ${fnType}${details}\n` + - `Actual message: ${actual && actual.message}`, + `Actual message: "${actual && actual.message}"`, stackStartFn }); } diff --git a/test/parallel/test-assert-async.js b/test/parallel/test-assert-async.js index b6b744c9b1e3ae..cc557d504ac6f2 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 a8891c980bc1af..389236b1ba0f38 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -131,7 +131,7 @@ assert.throws( code: 'ERR_ASSERTION', operator: 'doesNotThrow', message: 'Got unwanted exception: user message\n' + - 'Actual message: [object Object]' + 'Actual message: "[object Object]"' } ); @@ -139,7 +139,7 @@ assert.throws( () => a.doesNotThrow(() => thrower(Error)), { code: 'ERR_ASSERTION', - message: 'Got unwanted exception.\nActual message: [object Object]' + message: 'Got unwanted exception.\nActual message: "[object Object]"' } ); @@ -832,7 +832,7 @@ common.expectsError( { name: 'AssertionError [ERR_ASSERTION]', code: 'ERR_ASSERTION', - message: 'Got unwanted exception.\nActual message: undefined' + message: 'Got unwanted exception.\nActual message: "undefined"' } ); }