diff --git a/packages/pretty-format/src/__tests__/react.test.js b/packages/pretty-format/src/__tests__/react.test.js index f97190febb8d..f25d7b30187d 100644 --- a/packages/pretty-format/src/__tests__/react.test.js +++ b/packages/pretty-format/src/__tests__/react.test.js @@ -724,6 +724,7 @@ test('supports forwardRef with a child', () => { } expect( + // $FlowFixMe - https://github.com/facebook/flow/issues/6103 formatElement(React.createElement(React.forwardRef(Cat), null, 'mouse')), ).toEqual('\n mouse\n'); }); diff --git a/packages/pretty-format/src/plugins/react_element.js b/packages/pretty-format/src/plugins/react_element.js index 1d0a11bd5ba7..78b73be8ae2e 100644 --- a/packages/pretty-format/src/plugins/react_element.js +++ b/packages/pretty-format/src/plugins/react_element.js @@ -36,17 +36,16 @@ const getChildren = (arg, children = []) => { }; const getType = element => { - if (typeof element.type === 'string') { - return element.type; + const type = element.type; + if (typeof type === 'string') { + return type; } - if (typeof element.type === 'function') { - return element.type.displayName || element.type.name || 'Unknown'; + if (typeof type === 'function') { + return type.displayName || type.name || 'Unknown'; } - if (element.type === fragmentSymbol) { + if (type === fragmentSymbol) { return 'React.Fragment'; } - - const type = element.type; if (typeof type === 'object' && type !== null) { if (type.$$typeof === providerSymbol) { return 'Context.Provider';