assert: add more information to AssertionErrors

This adds information about the actual thrown error to the
AssertionError's message property.

It also improves the logged error instances error name by using the
constructors name, if available.

PR-URL: https://github.com/nodejs/node/pull/28263
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2019-06-15 13:27:21 +02:00
parent 5700cd17dd
commit 97c52ca5dc
No known key found for this signature in database
GPG key ID: F07496B3EB3C1762
3 changed files with 16 additions and 5 deletions

View file

@ -73,7 +73,8 @@ const invalidThenableFunc = () => {
() => assert.rejects(Promise.reject(err), validate),
{
message: 'The "validate" validation function is expected to ' +
"return \"true\". Received 'baz'",
"return \"true\". Received 'baz'\n\nCaught error:\n\n" +
'Error: foobar',
code: 'ERR_ASSERTION',
actual: err,
expected: validate,