-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix(pretty-format): Render custom displayName of memoized components #8546
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8546 +/- ##
=======================================
Coverage 60.57% 60.57%
=======================================
Files 269 269
Lines 11054 11054
Branches 2696 2696
=======================================
Hits 6696 6696
Misses 3772 3772
Partials 586 586
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, can you add a changelog entry? :)
@gustavovnicius Thank you. To make sure that I understand the situation:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing changelog, otherwise LGTM!
@pedrottimark >
Thinking back now, I believe it's better written without |
I added some more test cases, so I hope now it's a bit clearer |
Thanks! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Currently, the way
jest
andenzyme
handle memoized components is out of sync. This leads to some snapshot tests rendering the incorrect memoized component's displayName. e.g.: while using the latestreact-redux
version, some connected components are memoized and they respect the customdisplayName
, it can be checked here: https://github.com/reduxjs/react-redux/blob/master/src/components/connectAdvanced.js#L416.enzyme
has fixed it here: https://github.com/airbnb/enzyme/pull/2137/files, notice that it checks for the type's displayName, before going to the type's type displayName.Test plan
Prior to this, when a memoized/connected
React.Node
is passed as another component's props, the snapshot tests of that component would return<Memo(ConnectFunction)>
, now they return the correct component displayName instead:<Memo(Connect(MyComponent))>
You can check the wrong case here: https://github.com/gustavovnicius/enzyme-display-name-bug/blob/master/src/__snapshots__/App.test.js.snap#L6
In the snapshot, it should be
body={<Memo(Connect(Body)) />}
instead ofbody={<Memo(ConnectFunction) />}