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 e938784

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
assert: fix generatedMessage property
This makes sure the `generatedMessage` property is always set as expected. This was not the case some `assert.throws` and `assert.rejects` calls. Backport-PR-URL: #31431 PR-URL: #28263 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent fc0febe commit e938784
Copy full SHA for e938784

File tree

Expand file treeCollapse file tree

1 file changed

+10
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-3
lines changed
Open diff view settings
Collapse file

‎lib/assert.js‎

Copy file name to clipboardExpand all lines: lib/assert.js
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,21 @@ function expectedException(actual, expected, message, fn) {
578578
if (expected.test(str))
579579
return;
580580

581-
throw new AssertionError({
581+
if (!message) {
582+
generatedMessage = true;
583+
message = 'The input did not match the regular expression ' +
584+
`${inspect(expected)}. Input:\n\n${inspect(str)}\n`;
585+
}
586+
587+
const err = new AssertionError({
582588
actual,
583589
expected,
584-
message: message || 'The input did not match the regular expression ' +
585-
`${inspect(expected)}. Input:\n\n${inspect(str)}\n`,
590+
message,
586591
operator: fn.name,
587592
stackStartFn: fn
588593
});
594+
err.generatedMessage = generatedMessage;
595+
throw err;
589596
}
590597

591598
// Handle primitives properly.

0 commit comments

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