From eba44926eddd8947184c65de8a7aa7499ef82163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 2 Oct 2026 14:00:44 +0200 Subject: [PATCH] fix(pretty-format): support boxed symbols (fix #11445) (#11446) --- packages/pretty-format/src/index.ts | 2 +- test/unit/test/pretty-format.test.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/pretty-format/src/index.ts b/packages/pretty-format/src/index.ts index 646631806..89066428b 100644 --- a/packages/pretty-format/src/index.ts +++ b/packages/pretty-format/src/index.ts @@ -94,7 +94,7 @@ function printFunction(val: Function, printFunctionName: boolean): string { } function printSymbol(val: symbol): string { - return String(val).replace(SYMBOL_REGEXP, 'Symbol($1)') + return Symbol.prototype.toString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)') } function printError(val: Error): string { diff --git a/test/unit/test/pretty-format.test.ts b/test/unit/test/pretty-format.test.ts index 43ccc9b17..6894f30cb 100644 --- a/test/unit/test/pretty-format.test.ts +++ b/test/unit/test/pretty-format.test.ts @@ -293,6 +293,10 @@ describe('basic types', () => { expect(format(Symbol(''))).toMatchInlineSnapshot(`"Symbol()"`) }) + test('boxed symbol', () => { + expect(format(new Object(Symbol('test')))).toMatchInlineSnapshot(`"Symbol(test)"`) + }) + test('named function', () => { function named() {} expect(format(named)).toMatchInlineSnapshot(`"[Function named]"`) -- 2.51.2