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: #28263
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
BridgeAR committed Oct 1, 2019
1 parent ace3f16 commit 0b3242c
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 @@ -571,14 +571,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 0b3242c

Please sign in to comment.