From 4490282a159c40eaf937976fd7b11a560d5a3d07 Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Esun Date: Wed, 25 Apr 2018 17:59:48 +0100 Subject: [PATCH] Introduce forward references in pretty printer --- packages/pretty-format/src/plugins/react_element.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/pretty-format/src/plugins/react_element.js b/packages/pretty-format/src/plugins/react_element.js index bd261491c6b6..1fd2be25b83d 100644 --- a/packages/pretty-format/src/plugins/react_element.js +++ b/packages/pretty-format/src/plugins/react_element.js @@ -18,6 +18,7 @@ import { const elementSymbol = Symbol.for('react.element'); const fragmentSymbol = Symbol.for('react.fragment'); +const forwardRefSymbol = Symbol.for('react.forward_ref'); // Given element.props.children, or subtree during recursive traversal, // return flattened array of children. @@ -42,6 +43,14 @@ const getType = element => { if (element.type === fragmentSymbol) { return 'React.Fragment'; } + if (element.type === forwardRefSymbol) { + const functionName = + element.type.render.displayName || element.type.render.name || ''; + + return functionName !== '' + ? 'ForwardRef(' + functionName + ')' + : 'ForwardRef'; + } return 'UNDEFINED'; };