-
Notifications
You must be signed in to change notification settings - Fork 24.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
pass through the displayName from the mocked component #21429
Conversation
without this, most tooling will just say "Component" instead of "Text", "View" etc.
Thanks for contributing! This looks reasonable to me at first glance, but it is hard to tell from your test plan how I can reproduce the issue you are fixing. Can you provide a minimal jest test that reproduces this error if your fix wasn't included? Better yet, can you add a jest test for |
Sure thing, I'll add a test |
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.
Code analysis results:
eslint
found some issues.eslint
found some issues.eslint
found some issues.
jest/__mocks__/FakeComponent.js
Outdated
@@ -0,0 +1 @@ | |||
export default () => null |
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.
semi: Missing semicolon.
jest/__tests__/mockComponent-test.js
Outdated
@@ -0,0 +1,13 @@ | |||
const mockComponent = require('../mockComponent'); | |||
const FakeComponent = require('FakeComponent') |
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.
semi: Missing semicolon.
jest/__tests__/mockComponent-test.js
Outdated
@@ -0,0 +1,13 @@ | |||
const mockComponent = require('../mockComponent'); | |||
const FakeComponent = require('FakeComponent') | |||
const TextInput = require('TextInput') |
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.
semi: Missing semicolon.
Side question, why was this done? 76eebce#diff-a562e4a7ac9e900c6d2bc644453e9152 The displayName was removed from a bunch of components which is kind of a mistake because it makes them hard to identify in devtools and react warnings. |
Our understanding is that React.forwardRef was updated to utilize the displayName of the passed in component so those lines were no longer necessary. |
It doesn’t as far as I know. It just respects if you set a displayName on
the forwardRef
…On Sun, Sep 30, 2018 at 11:12 PM Eli White ***@***.***> wrote:
Our understanding is that React.forwardRef was updated to utilize the
displayName of the passed in component so those lines were no longer
necessary.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#21429 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAiy1gz4YZRe0Nai_Qcsl6j-2GTODP8fks5ugZY5gaJpZM4XBJes>
.
|
Hmm. I’m not on a computer to test it out but the docs for forwardRef at least seem to indicate that it has some special behavior for displayName. https://reactjs.org/docs/forwarding-refs.html |
@TheSavior The behavior is if you set a displayName on the ForwardRef wrapper it'll take it into account in devtools I believe. |
Generated by 🚫 dangerJS |
@TheSavior I think devtools is kind of a special case since it literally executes the render function of the forwardRef to obtain the underlying component and then shows the displayName as a derivation of that. Enzyme and other tooling likely will not go to that length since the fact that forwardRef has a function called "render" is an implementation detail and not part of the public API. I actually wrote the change that was recently merged into react core to start directly honoring |
Okay, so to make sure I understand, is your request that we add back the annotations to all the components that use It seems like that will be hard to enforce everywhere forwardRef is used and is a workaround that adds runtime code to help make build and test time tooling easier. Am I misunderstanding something? |
I’d say that’s phase 2 of this PR/changeset, yes. I’m not sure what other
recourse there is without having React core do displayName as a getter for
forwardRef and emulating the same behavior as devtools because most testing
output becomes less useful without the names.
…On Mon, Oct 1, 2018 at 5:19 PM Eli White ***@***.***> wrote:
Okay, so to make sure I understand, is your request that we add back the
annotations to all the components that use forwardRef so that tooling
like enzyme is able to read those names?
It seems like that will be hard to enforce everywhere forwardRef is used
and is a workaround that adds runtime code to help make build and test time
tooling easier. Am I misunderstanding something?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#21429 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAiy1nhEQNUFboHZwipSlQJEC6BMUcu0ks5ugpUHgaJpZM4XBJes>
.
|
And actually that wouldn’t even work consistently because it’s entirely
possible to dynamically render different things inside the forwardRef
render based on props.
…On Mon, Oct 1, 2018 at 7:03 PM Evan Jacobs ***@***.***> wrote:
I’d say that’s phase 2 of this PR/changeset, yes. I’m not sure what other
recourse there is without having React core do displayName as a getter for
forwardRef and emulating the same behavior as devtools because most testing
output becomes less useful without the names.
On Mon, Oct 1, 2018 at 5:19 PM Eli White ***@***.***> wrote:
> Okay, so to make sure I understand, is your request that we add back the
> annotations to all the components that use forwardRef so that tooling
> like enzyme is able to read those names?
>
> It seems like that will be hard to enforce everywhere forwardRef is used
> and is a workaround that adds runtime code to help make build and test time
> tooling easier. Am I misunderstanding something?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#21429 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAiy1nhEQNUFboHZwipSlQJEC6BMUcu0ks5ugpUHgaJpZM4XBJes>
> .
>
|
I'm gonna close this as there hasn't been progress in many months and the conclusion seems to be that this isn't what we want to do. |
Without this, most tooling will just say "Component" instead of "Text", "View" etc.
Test Plan:
Copied the change over and verified that it worked locally in the styled-components tests.
Release Notes:
[INTERNAL] [BUGFIX] [jest/mockComponent.js] - resume passing the mocked component's displayName through so it will appear in downstream tooling