-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Jest/Enzyme snapshots show 'Component' instead of the native component #21937
Comments
It seems like |
Yes; you’d have to explicitly set a displayName property on the forwardRef to get it to show up. |
Aha, thanks @ljharb ! It looks like they tried to do that but ran into a problem, so they removed it ( |
Summary: Adds the displayName prop to `View` and `Text` components. Because these now use `React.forwardRef`, they were showing as `Component` instead of their actual names. Thanks to ljharb for helping to pinpoint the source of the issue! Fixes #21937 Pull Request resolved: #21950 Differential Revision: D12827060 Pulled By: TheSavior fbshipit-source-id: d812cae14d53ad821ab5873e737db63ad1a989e3
Summary: Similar to #21950, this adds displayName to `ActivityIndicator`, so it displays the correct component name in snapshots instead of `Component`. Fixes #21937 (a little bit more than it was already fixed). Pull Request resolved: #22417 Differential Revision: D13205376 Pulled By: TheSavior fbshipit-source-id: 21e71d4980d159a1f33d32d83346b48257ec21d4
Summary: Similar to #21950, this adds displayName to `ActivityIndicator`, so it displays the correct component name in snapshots instead of `Component`. Fixes #21937 (a little bit more than it was already fixed). Pull Request resolved: #22417 Differential Revision: D13205376 Pulled By: TheSavior fbshipit-source-id: 21e71d4980d159a1f33d32d83346b48257ec21d4
Summary: This diff adds a custom matcher which will wrap a given component and shallow render it, snapshotting the result with the formatting users will see when they do the same. I also update the ActivityIndicator test to use this new strategy, and add an additional check that the displayName is set. For context see: - #21950 - https://github.com/rajivshah3/rn-broken-snapshot/blob/broken-example/__tests__/App.spec.js#L3 - #21937 Reviewed By: TheSavior Differential Revision: D13326689 fbshipit-source-id: 8ed2302a8aad12962fa2498a46d2502ccfb5c737
Summary: Similar to #21950, this adds displayName to `ActivityIndicator`, so it displays the correct component name in snapshots instead of `Component`. Fixes #21937 (a little bit more than it was already fixed). Pull Request resolved: #22417 Differential Revision: D13205376 Pulled By: TheSavior fbshipit-source-id: 21e71d4980d159a1f33d32d83346b48257ec21d4
Summary: This diff adds a custom matcher which will wrap a given component and shallow render it, snapshotting the result with the formatting users will see when they do the same. I also update the ActivityIndicator test to use this new strategy, and add an additional check that the displayName is set. For context see: - #21950 - https://github.com/rajivshah3/rn-broken-snapshot/blob/broken-example/__tests__/App.spec.js#L3 - #21937 Reviewed By: TheSavior Differential Revision: D13326689 fbshipit-source-id: 8ed2302a8aad12962fa2498a46d2502ccfb5c737
@rajivshah3 did your fix get released in a new RN version yet? |
Seems to have fixed all my tests when I just upgraded RN from 0.57.0 ---> 0.57.8 Thanks guys :) |
Yep, it was included in 0.57.5
… On Jan 22, 2019, at 7:45 AM, James McNamara ***@***.***> wrote:
Seems to have fixed all my tests when I just upgraded from 0.57.0 ---> 0.57.8
Thanks guys :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Still seeing this issue in |
@linnett it looks like the same issue. They moved to react-native/Libraries/Image/Image.ios.js Line 126 in 842b9c1
If you want to do a PR for this, I think specifying Image = React.forwardRef(Image);
Image.displayName = 'Image'; That's essentially what I did to fix |
Good shout @rajivshah3 - PR: #23287 |
…ts (#23287) Summary: As per #21937, Image `displayName` is not set. This means it comes through as `<Component>` in tests. [General][fixed] - fix `displayName` for `Image` Pull Request resolved: #23287 Differential Revision: D13941744 Pulled By: cpojer fbshipit-source-id: eab161eee415ec4f7207efcd5c6e2a4bbe67dfe1
…ts (facebook#23287) Summary: As per facebook#21937, Image `displayName` is not set. This means it comes through as `<Component>` in tests. [General][fixed] - fix `displayName` for `Image` Pull Request resolved: facebook#23287 Differential Revision: D13941744 Pulled By: cpojer fbshipit-source-id: eab161eee415ec4f7207efcd5c6e2a4bbe67dfe1
Summary: Adds the displayName prop to `View` and `Text` components. Because these now use `React.forwardRef`, they were showing as `Component` instead of their actual names. Thanks to ljharb for helping to pinpoint the source of the issue! Fixes facebook#21937 Pull Request resolved: facebook#21950 Differential Revision: D12827060 Pulled By: TheSavior fbshipit-source-id: d812cae14d53ad821ab5873e737db63ad1a989e3
Summary: Similar to facebook#21950, this adds displayName to `ActivityIndicator`, so it displays the correct component name in snapshots instead of `Component`. Fixes facebook#21937 (a little bit more than it was already fixed). Pull Request resolved: facebook#22417 Differential Revision: D13205376 Pulled By: TheSavior fbshipit-source-id: 21e71d4980d159a1f33d32d83346b48257ec21d4
Summary: This diff adds a custom matcher which will wrap a given component and shallow render it, snapshotting the result with the formatting users will see when they do the same. I also update the ActivityIndicator test to use this new strategy, and add an additional check that the displayName is set. For context see: - facebook#21950 - https://github.com/rajivshah3/rn-broken-snapshot/blob/broken-example/__tests__/App.spec.js#L3 - facebook#21937 Reviewed By: TheSavior Differential Revision: D13326689 fbshipit-source-id: 8ed2302a8aad12962fa2498a46d2502ccfb5c737
Environment
Description
In React Native 0.57, the snapshots taken by Jest and Enzyme show
Component
instead of the actual native component (e.g.View
,Text
). See diff. This is not only an issue when used with Jest, but also with Enzyme (enzymejs/enzyme#1743).Reproducible Demo
This can be reproduced by simply upgrading
react-native
as shown here.A full example is located at https://github.com/rajivshah3/rn-broken-snapshot. The
master
branch is the latest version of React Native with a working snapshot test, the0.55
branch is v0.55 of React Native, andbroken-example
is an example of a project that is trying to upgrade from v0.55 to the latest version.The text was updated successfully, but these errors were encountered: