Skip to content
Prev Previous commit
Next Next commit
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.
  • Loading branch information
BridgeAR committed Jun 15, 2019
commit f90cfca8f1ea4922122dc95582678e9f52e138c4
13 changes: 10 additions & 3 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,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