assert: support symbols as assertion messages

Currently, assertion messages are implicitly converted to strings,
which causes symbols to throw. This commit adds an explicit
string conversion.

PR-URL: https://github.com/nodejs/node/pull/20693
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
cjihrig authored and Myles Borins committed 2018-05-22 14:09:48 -04:00
1 parent 0d28b4b6ba
commit 1160d61cd9
2 files changed
+11 -1

No files matched your search

+1 -1
View File
@@ -196,7 +196,7 @@ class AssertionError extends Error {
} = options;
if (message != null) {
super(message);
super(String(message));
} else {
if (process.stdout.isTTY) {
// Reset on each call to make sure we handle dynamically set environment
+10
View File
@@ -640,6 +640,16 @@ common.expectsError(
}
);
common.expectsError(
() => assert(false, Symbol('foo')),
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
generatedMessage: false,
message: 'Symbol(foo)'
}
);
{
// Test caching.
const fs = process.binding('fs');