You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 10, 2025. It is now read-only.
I was recently testing some stuff in web when I came across a case where react-testing was not returning the name of a component correctly and was instead falling back to the default of "Component"
● <FileInsuranceClaim /> › on save › with errors › displays server error toast and restore submit button if server error occurs
expect(received).toContainReactComponent(expected)
Expected the React element:
<Async(FileInsuranceClaim) />
To contain component:
<Component />
But no matching <Component /> elements were found.
1438 | await submit(fileInsuranceClaim);
1439 |
> 1440 | expect(fileInsuranceClaim).toContainReactComponent(Toast);
I would have expected that to say:
To contain component:
<Toast />
I believe this is because this Toast component in question is the one from polaris which is a Component wrapped in a React.memo, rather than a plain old functional component.
I suspect this is because the printType utility does not correctly handle finding the name for components that are wrapped in React.memo(). I'd wager components wrapped in React.forwardRef() are also affected in the same way. You should also test components that are do React.memo(React.forwardRef(function SomeComponent() { return 'hi'; }))
facebook/react#17274 from the react repo might be some useful related reading as it fixes up some logic around how names are extracted from these exotic components in the react dev tools.
Overview
I was recently testing some stuff in web when I came across a case where react-testing was not returning the name of a component correctly and was instead falling back to the default of "Component"
I would have expected that to say:
I believe this is because this Toast component in question is the one from polaris which is a Component wrapped in a React.memo, rather than a plain old functional component.
I suspect this is because the printType utility does not correctly handle finding the name for components that are wrapped in
React.memo(). I'd wager components wrapped inReact.forwardRef()are also affected in the same way. You should also test components that are doReact.memo(React.forwardRef(function SomeComponent() { return 'hi'; }))facebook/react#17274 from the react repo might be some useful related reading as it fixes up some logic around how names are extracted from these exotic components in the react dev tools.