From e02ca8278f079f253c31e1f77f661e028ebf7db1 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Tue, 1 May 2018 13:23:22 +0100 Subject: [PATCH] Code review fixes --- packages/pretty-format/src/__tests__/react.test.js | 1 + packages/pretty-format/src/plugins/react_element.js | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) 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';