-
Notifications
You must be signed in to change notification settings - Fork 47.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-test-renderer: the findByType method doesn't work with memo components #17301
Comments
I think this is a bug, likely fixed by #17278 |
If you debug the result tree, the memo component does not exist, only the component that it wrapped. I believe this is by design? Since the tree is the "reconciled" tree. Would need to dig further. Edit: Tested on v16.12. The PR above didn't fix this. |
@milesj indeed, v16.12 didn't fix this problem. If |
I've found a workaround for those that need it. Pin |
I am having the same issue. One thing that I found is that if |
Also having this issue. @henryqdineen I tried defining the |
See my comment on #17700 (comment). |
I ended up creating my own test predicate until this is resolved: const MyComponent = () => (<div />);
const MemoMyComponent = React.memo(MyComponent);
const elementByType = (type) => (element) => (
element.type === type // Match non-memo'd
|| element.type === type.type // Match memo'd
);
const rendered = renderer.create((
<MyComponent />
));
rendered.root.find(elementByType(MyComponent))
const renderedWithMemo = renderer.create((
<MemoMyComponent />
));
renderedWithMemo.root.find(elementByType(MemoMyComponent)) |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Whenever I try something like:
I get the following error:
No instances found with node type: "undefined"
. The only way I found for this to work was to reference thetype
property of memo components like this:I am fine with this solution but then flow complains that
type
doesn't exist so I find myself fixing this with$FlowFixMe
all over the place.What is the expected behavior?
I would expect that passing a memo component to
findByType
would work. Or that flow would recognize thetype
property of memo components. I think both should work, specially the first option.Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
No, it never worked as far as I know.
The text was updated successfully, but these errors were encountered: