Skip to content

Commit

Permalink
assert: fix generatedMessage property
Browse files Browse the repository at this point in the history
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: nodejs#28263
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR committed Jan 22, 2020
1 parent 9c9b338 commit 32dfdb8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,21 @@ function expectedException(actual, expected, message, fn) {
if (expected.test(str))
return;

throw new AssertionError({
if (!message) {
generatedMessage = true;
message = 'The input did not match the regular expression ' +
`${inspect(expected)}. Input:\n\n${inspect(str)}\n`;
}

const err = new AssertionError({
actual,
expected,
message: message || 'The input did not match the regular expression ' +
`${inspect(expected)}. Input:\n\n${inspect(str)}\n`,
message,
operator: fn.name,
stackStartFn: fn
});
err.generatedMessage = generatedMessage;
throw err;
}

// Handle primitives properly.
Expand Down

0 comments on commit 32dfdb8

Please sign in to comment.