From c9d84b6d4f792831a6d88e902c6ddf11e38b9e7e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 15 Dec 2017 21:09:12 -0200 Subject: [PATCH] assert: fix throws and doesNotThrow stack frames The stack frames from .throws and .doesNotThrow got included even though that was not intended. Backport-PR-URL: https://github.com/nodejs/node/pull/23223 PR-URL: https://github.com/nodejs/node/pull/17703 Reviewed-By: Timothy Gu Reviewed-By: James M Snell --- lib/assert.js | 4 ++-- test/parallel/test-assert.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 092208c8c8e825..79c61fa7559a16 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -709,7 +709,7 @@ function innerThrows(shouldThrow, block, expected, message) { expected, operator: 'throws', message: `Missing expected exception${details}`, - stackStartFn: innerThrows + stackStartFn: assert.throws }); } if (expected && expectedException(actual, expected) === false) { @@ -723,7 +723,7 @@ function innerThrows(shouldThrow, block, expected, message) { expected, operator: 'doesNotThrow', message: `Got unwanted exception${details}`, - stackStartFn: innerThrows + stackStartFn: assert.doesNotThrow }); } throw actual; diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 2d5b38d0dceb02..a8ba1bf5d1fc6d 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -603,6 +603,7 @@ testAssertionMessage({ a: NaN, b: Infinity, c: -Infinity }, } catch (e) { threw = true; assert.strictEqual(e.message, 'Missing expected exception.'); + assert.ok(!e.stack.includes('throws'), e.stack); } assert.ok(threw); } @@ -619,8 +620,8 @@ try { assert.strictEqual(1, 2, 'oh no'); // eslint-disable-line no-restricted-syntax } catch (e) { assert.strictEqual(e.message.split('\n')[0], 'oh no'); - // Message should not be marked as generated. - assert.strictEqual(e.generatedMessage, false); + assert.strictEqual(e.generatedMessage, false, + 'Message incorrectly marked as generated'); } {