mirror of https://github.com/nodejs/node.git
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>pull/20693/head
parent
ee2a7703e7
commit
810af50ba2
|
@ -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
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue