Skip to content

Commit 0b3242c

Browse files
committed
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. PR-URL: #28263 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ace3f16 commit 0b3242c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/assert.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -571,14 +571,21 @@ function expectedException(actual, expected, message, fn) {
571571
if (expected.test(str))
572572
return;
573573

574-
throw new AssertionError({
574+
if (!message) {
575+
generatedMessage = true;
576+
message = 'The input did not match the regular expression ' +
577+
`${inspect(expected)}. Input:\n\n${inspect(str)}\n`;
578+
}
579+
580+
const err = new AssertionError({
575581
actual,
576582
expected,
577-
message: message || 'The input did not match the regular expression ' +
578-
`${inspect(expected)}. Input:\n\n${inspect(str)}\n`,
583+
message,
579584
operator: fn.name,
580585
stackStartFn: fn
581586
});
587+
err.generatedMessage = generatedMessage;
588+
throw err;
582589
}
583590

584591
// Handle primitives properly.

0 commit comments

Comments
 (0)