Skip to content

Commit eba4492

Browse files
authored
fix(pretty-format): support boxed symbols (fix #11445) (#11446)
1 parent e1a7314 commit eba4492

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎packages/pretty-format/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function printFunction(val: Function, printFunctionName: boolean): string {
9494
}
9595

9696
function printSymbol(val: symbol): string {
97-
return String(val).replace(SYMBOL_REGEXP, 'Symbol($1)')
97+
return Symbol.prototype.toString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)')
9898
}
9999

100100
function printError(val: Error): string {

‎test/unit/test/pretty-format.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ describe('basic types', () => {
293293
expect(format(Symbol(''))).toMatchInlineSnapshot(`"Symbol()"`)
294294
})
295295

296+
test('boxed symbol', () => {
297+
expect(format(new Object(Symbol('test')))).toMatchInlineSnapshot(`"Symbol(test)"`)
298+
})
299+
296300
test('named function', () => {
297301
function named() {}
298302
expect(format(named)).toMatchInlineSnapshot(`"[Function named]"`)

0 commit comments

Comments
 (0)