From 6b714314d87238294572e3e6152e9270cfcfc854 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/19230 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 | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 0f3541bc10d7bb..cb590ca8af0c2b 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -245,7 +245,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) { @@ -259,7 +259,7 @@ function innerThrows(shouldThrow, block, expected, message) { expected, operator: 'doesNotThrow', message: `Got unwanted exception${details}\n${actual.message}`, - stackStartFn: innerThrows + stackStartFn: assert.doesNotThrow }); } throw actual; diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index cd29639f935a48..95b4f9513296af 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -634,6 +634,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); } @@ -678,6 +679,7 @@ try { threw = true; assert.ok(e.message.includes(rangeError.message)); assert.ok(e instanceof assert.AssertionError); + assert.ok(!e.stack.includes('doesNotThrow'), e.stack); } assert.ok(threw); }