Skip to content

Commit

Permalink
assert: fix throws and doesNotThrow stack frames
Browse files Browse the repository at this point in the history
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 <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed Oct 31, 2018
1 parent a42d072 commit c9d84b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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');
}

{
Expand Down

0 comments on commit c9d84b6

Please sign in to comment.