Snapshot tests showing components as '<ForwardRef />' instead of component name
See original GitHub issueemotion
version:
"@emotion/core": "^10.0.6",
"@emotion/native": "^10.0.6",
react
version:
"react": "16.6.3",
"react-native": "0.57.8",
Relevant code:
const StyledText = styled.Text<StyledTextProps>`
${space}
${textType}
${textAlign}
${textColor}
`;
StyledText.defaultProps = {
type: 'default',
};
StyledText.displayName = 'StyledText';
What you did:
Used the StyledText
component I just created in another component and did a snapshot test.
What happened:
I expected the name in the snapshots to show up as <StyledText ...>
but it showed up as <ForwardRef ...>
instead.
Suggested solution: The displayName should be honoured when created styled components like this, or at least there should be an API to provide that name to emotion.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:18 (12 by maintainers)
Top Results From Across the Web
ForwardRef component error: jest react native - Stack Overflow
Here is What I have done to resolve this problem: Just add this function : jest.mock("react", () => { const originReact = jest....
Read more >What does forwardRef by a component in React dev tools ...
The forwardRef calls aren't in your own code, they are in the packages that you are using. styled.button appears to be from styled-components...
Read more >Continuous integration for React applications using Jest and ...
I recommend using snapshot testing to track changes to components. In this method, you take snapshots of components and when the component's ......
Read more >Use with React - Styletron
Since styled is technically a higher-order component, we need to set the displayName explicitly to see the real component name when debugging (or...
Read more >Snapshot Testing - Jest
A typical snapshot test case renders a UI component, ... A similar approach can be taken when it comes to testing your React...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Got around this by not applying
@emotion/babel-preset-css-prop
specifically for test babel config, eg:But yeah maybe not the best way - ideally should work out of the box
Hi all, this might be have been fixed in this pr: https://github.com/emotion-js/emotion/pull/1280 We just merged it, so it might be a couple of days until it’s released.
@mitchellhamilton how often do you cut new releases?