Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 84948cf

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
assert: fix .throws operator
assert.throws and assert.doesNotThrow set the operator to a internal function. That was by accident and originally the operator was undefined. This changes it to show "throws" or "doesNotThrow". Backport-PR-URL: #23223 PR-URL: #17575 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
1 parent c6d94f8 commit 84948cf
Copy full SHA for 84948cf

File tree

Expand file treeCollapse file tree

2 files changed

+16
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-7
lines changed
Open diff view settings
Collapse file

‎lib/assert.js‎

Copy file name to clipboardExpand all lines: lib/assert.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,18 @@ function innerThrows(shouldThrow, block, expected, message) {
643643
details += ` (${expected.name})`;
644644
}
645645
details += message ? `: ${message}` : '.';
646-
fail(actual, expected, `Missing expected exception${details}`, fail);
646+
fail(actual, expected, `Missing expected exception${details}`, 'throws');
647647
}
648648
if (expected && expectedException(actual, expected) === false) {
649649
throw actual;
650650
}
651651
} else if (actual !== undefined) {
652652
if (!expected || expectedException(actual, expected)) {
653653
details = message ? `: ${message}` : '.';
654-
fail(actual, expected, `Got unwanted exception${details}`, fail);
654+
fail(actual,
655+
expected,
656+
`Got unwanted exception${details}`,
657+
'doesNotThrow');
655658
}
656659
throw actual;
657660
}
Collapse file

‎test/parallel/test-assert.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert.js
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,15 @@ assert.throws(() => { assert.ifError(new Error('test error')); },
463463
assert.doesNotThrow(() => { assert.ifError(null); });
464464
assert.doesNotThrow(() => { assert.ifError(); });
465465

466-
assert.throws(() => {
467-
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
468-
}, /Got unwanted exception: user message/,
469-
'a.doesNotThrow ignores user message');
466+
common.expectsError(
467+
() => assert.doesNotThrow(makeBlock(thrower, Error), 'user message'),
468+
{
469+
type: a.AssertionError,
470+
code: 'ERR_ASSERTION',
471+
operator: 'doesNotThrow',
472+
message: 'Got unwanted exception: user message\n[object Object]'
473+
}
474+
);
470475

471476
// make sure that validating using constructor really works
472477
{
@@ -525,7 +530,8 @@ a.throws(makeBlock(thrower, TypeError), (err) => {
525530
() => { a.throws((noop)); },
526531
common.expectsError({
527532
code: 'ERR_ASSERTION',
528-
message: /^Missing expected exception\.$/
533+
message: /^Missing expected exception\.$/,
534+
operator: 'throws'
529535
}));
530536

531537
assert.throws(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.