Skip to content

Commit c9d84b6

Browse files
BridgeARMylesBorins
authored andcommitted
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: #23223 PR-URL: #17703 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a42d072 commit c9d84b6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/assert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ function innerThrows(shouldThrow, block, expected, message) {
709709
expected,
710710
operator: 'throws',
711711
message: `Missing expected exception${details}`,
712-
stackStartFn: innerThrows
712+
stackStartFn: assert.throws
713713
});
714714
}
715715
if (expected && expectedException(actual, expected) === false) {
@@ -723,7 +723,7 @@ function innerThrows(shouldThrow, block, expected, message) {
723723
expected,
724724
operator: 'doesNotThrow',
725725
message: `Got unwanted exception${details}`,
726-
stackStartFn: innerThrows
726+
stackStartFn: assert.doesNotThrow
727727
});
728728
}
729729
throw actual;

test/parallel/test-assert.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ testAssertionMessage({ a: NaN, b: Infinity, c: -Infinity },
603603
} catch (e) {
604604
threw = true;
605605
assert.strictEqual(e.message, 'Missing expected exception.');
606+
assert.ok(!e.stack.includes('throws'), e.stack);
606607
}
607608
assert.ok(threw);
608609
}
@@ -619,8 +620,8 @@ try {
619620
assert.strictEqual(1, 2, 'oh no'); // eslint-disable-line no-restricted-syntax
620621
} catch (e) {
621622
assert.strictEqual(e.message.split('\n')[0], 'oh no');
622-
// Message should not be marked as generated.
623-
assert.strictEqual(e.generatedMessage, false);
623+
assert.strictEqual(e.generatedMessage, false,
624+
'Message incorrectly marked as generated');
624625
}
625626

626627
{

0 commit comments

Comments
 (0)