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]"`)