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: #19230
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 Mar 20, 2018
1 parent db73d1c commit 24aeca7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/assert.js
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-assert.js
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 24aeca7

Please sign in to comment.