Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: fix .throws operator #17575

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/assert.js
Expand Up @@ -180,7 +180,7 @@ function innerThrows(shouldThrow, block, expected, message) {
details += ` (${expected.name})`;
}
details += message ? `: ${message}` : '.';
fail(actual, expected, `Missing expected exception${details}`, fail);
fail(actual, expected, `Missing expected exception${details}`, 'throws');
}
if (expected && expectedException(actual, expected) === false) {
throw actual;
Expand All @@ -191,7 +191,7 @@ function innerThrows(shouldThrow, block, expected, message) {
fail(actual,
expected,
`Got unwanted exception${details}\n${actual.message}`,
fail);
'doesNotThrow');
}
throw actual;
}
Expand Down
16 changes: 11 additions & 5 deletions test/parallel/test-assert.js
Expand Up @@ -466,10 +466,15 @@ assert.throws(() => { assert.ifError(new Error('test error')); },
assert.doesNotThrow(() => { assert.ifError(null); });
assert.doesNotThrow(() => { assert.ifError(); });

assert.throws(() => {
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
}, /Got unwanted exception: user message/,
'a.doesNotThrow ignores user message');
common.expectsError(
() => assert.doesNotThrow(makeBlock(thrower, Error), 'user message'),
{
type: a.AssertionError,
code: 'ERR_ASSERTION',
operator: 'doesNotThrow',
message: 'Got unwanted exception: user message\n[object Object]'
}
);

{
let threw = false;
Expand Down Expand Up @@ -556,7 +561,8 @@ a.throws(makeBlock(thrower, TypeError), (err) => {
() => { a.throws((noop)); },
common.expectsError({
code: 'ERR_ASSERTION',
message: /^Missing expected exception\.$/
message: /^Missing expected exception\.$/,
operator: 'throws'
}));

assert.throws(
Expand Down