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
The name() returned for memo()-wrapped components with defaultProps doesn't match the component's displayName itself in mount mode, and find calls using that name don't match those nodes.
Expected behavior
For a node that corresponds to an instance of a memo() component, name() should match the component's displayName, and find(MemoComponent.displayName) should match those nodes.
You're passing an arrow function (thus unnamed) component into memo which is obscuring the issue; in https://codesandbox.io/s/enzyme-memo-name-bug-vsflz, it's using a named function component, and you can see that the memo is automatically being unwrapped, and the memoized component is what you're interacting with.
The difference here is between mount and shallow - mount wraps what you pass to it, but shallow wraps what the thing renders - and mount punches through memo automatically by virtue of deeply rendering.
In other words, this is correct behavior, albeit confusing.
If you compare this behavior to how actual React behaves, with the dev tools extension, I believe (but I might be wrong!) that the displayName property on memo is ignored, and that only the memoized component's name matters.
I'll close this for now, but will reopen and fix if I'm wrong about how memo's displayName works.
It looks like you're right: This is a quirk of React, not Enzyme. 😞
Actually, searching the issue tracker there, it looks like a fix was merged just a few days ago: mui/material-ui#19762 😀 Whoops, that PR is a workaround for the material-ui library. Very much still an open bug in React: facebook/react#15207 😭
Very similar to #2332
Current behavior
The
name()
returned formemo()
-wrapped components withdefaultProps
doesn't match the component'sdisplayName
itself inmount
mode, andfind
calls using that name don't match those nodes.Expected behavior
For a node that corresponds to an instance of a
memo()
component,name()
should match the component'sdisplayName
, andfind(MemoComponent.displayName)
should match those nodes.Your environment
Try this: https://codesandbox.io/s/enzyme-memo-name-bug-435hq
API
Version
Adapter
The text was updated successfully, but these errors were encountered: