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
{{ message }}
Repository navigation
Migration guide from @testing-library/react-native is missing some breaking changes #477
Stoked to see the two react-native testing libraries have finally merged! At Root, we have a fair number of testing library tests in our react native project. I tried upgrading @testing-library/react-native from v6 to v7 and about 20% of our tests are failing after following the upgrade guide.
Another engineer will be taking a closer look at the upgrade (I was just trying to get an idea of the effort involved), but looking through the errors I see at least the following undocumented breaking changes:
parentNode is undefined (see https://www.native-testing-library.com/docs/api-test-instance#parentnode) -- this one is really important for us as we use it a lot for testing styles in cases where we can guarantee what the "native" parent will be. From a quick check I'm not sure if there is a new equivalent (.parent behaves differently since there's no concept of a NativeTestInstance now)
If there are existing ways to migrate from these old patterns to the new ones, we'd love to hear it and see it added to the migration guide. If not -- we'd likely be happy to contribute to add some of this functionality back in!
Hey! I think we can definitely add some of these back. I'm not so sure about parentNode because it smells like testing implementation details.
I'll be away from keyboard till next week, but I'm sure you can discuss it with @mdjastrzebski@Esemesek and @cross19xx and figure out the way forward 🙂
Hey @TAGraves would you be so kind and create some action points / issues for us to implement? For example baseElement sounds like something that should be fairly easy to start with. Then we could add string precision API, because why not. The more compat with Testing Library, the better. I hope it's understandable that we started from a different place, but we have all the good intentions :)
I also noticed that you were a collaborator to the second library, so if you'd like to gain more privileges in this repo, please give me a shout at Discord (thymikee#1279) :)
+1 for baseElement/Container. We use that at our company as a way to get at top level component which is useful in some cases where you don't have any specific text/content to query for
Another behavior that I noticed while doing migration is:
Before the query would return NativeTestInstance and it now return ReactTestInstance. This is already documented in the migration doc
However, this does break existing tests in our codebase because our tests expect to query on the same element seeing in debug() which would have type View, Text... whereas ReactTestInstance's type the React component itself. This seems to go against the philosophy of not testing the implementation.
The use case for us is to query the output style on a component
Appreciate direction if I am not using the new lib correctly
Thank you for your response @mdjastrzebski , I meant debug
This is a simplify example of the test that used to pass pre-v7. To get this test pass in the new version, we had to modify the test to check the prop of child(which is now an instance of ChildrenComponent instead of view. To me, checking style would follow closer to the not testing implementation details philosophy
Activity
thymikee commentedon Aug 2, 2020
Hey! I think we can definitely add some of these back. I'm not so sure about parentNode because it smells like testing implementation details.
I'll be away from keyboard till next week, but I'm sure you can discuss it with @mdjastrzebski @Esemesek and @cross19xx and figure out the way forward 🙂
TAGraves commentedon Aug 3, 2020
Yes, I agree. I think we can probably get around it in our codebase by adding a matcher that recursively checks parents for the appropriate styles.
manuelmhtr commentedon Aug 3, 2020
Also:
asJSONdoes not exist. It need to be renamed totoJSON.artdent commentedon Aug 13, 2020
Also the
getNodeTexthelper function, https://github.com/testing-library/native-testing-library/blob/master/src/lib/get-node-text.js, which could be replaced by a thin wrapper around the internalgetChildrenAsTexthelper.thymikee commentedon Aug 17, 2020
Hey @TAGraves would you be so kind and create some action points / issues for us to implement? For example
baseElementsounds like something that should be fairly easy to start with. Then we could add string precision API, because why not. The more compat with Testing Library, the better. I hope it's understandable that we started from a different place, but we have all the good intentions :)I also noticed that you were a collaborator to the second library, so if you'd like to gain more privileges in this repo, please give me a shout at Discord (
thymikee#1279) :)mdjastrzebski commentedon Aug 31, 2020
re
parentNode: I've added "Ability to traverse host component tree easily (discussion)" #520.dephiros commentedon Sep 25, 2020
+1 for baseElement/Container. We use that at our company as a way to get at top level component which is useful in some cases where you don't have any specific text/content to query for
dephiros commentedon Sep 25, 2020
Another behavior that I noticed while doing migration is:
NativeTestInstanceand it now returnReactTestInstance. This is already documented in the migration docdebug()which would have typeView,Text... whereasReactTestInstance's type the React component itself. This seems to go against the philosophy of not testing the implementation.Appreciate direction if I am not using the new lib correctly
mdjastrzebski commentedon Sep 26, 2020
@dephiros Please post sample test code of how are you using
debug().AFAIK
debugis intended to output to console. Did you actually meantoJSON()?thymikee commentedon Sep 28, 2020
I think we could introduce something similar to
NativeTestInstance, will need to think about it.dephiros commentedon Sep 28, 2020
Thank you for your response
@mdjastrzebski , I meant
debugThis is a simplify example of the test that used to pass pre-v7. To get this test pass in the new version, we had to modify the test to check the prop of
child(which is now an instance ofChildrenComponentinstead of view. To me, checking style would follow closer to the not testing implementation details philosophyview.debug() (very similar to the previous version except the previous version has the extra wrapper)
mikeduminy commentedon Oct 12, 2020
Here is an attempt to track all the functionality that IMO we should try to get in for v8
Missing functionality in v7 that was present in v6:
asJSONmissingcontainermissing (related feat: exportcontainerfrom render #567)baseElementmissing (breaking change for those using snapshots)Bugs in v7:
waitForcan time out if you are using fake timers (solved by fix(breaking): use real timers internally to fix awaiting with fake timers #568)Misc:
TouchableOpacityandTouchableHighlight(not present in react-native preset, affecting snapshots)What we can probably ignore until we have further information:
getProp,parentNodemdjastrzebski commentedon Aug 9, 2022
Closing as stale.
In case anyone involved considers any of the above mentioned points as a bug or missing feature, please fill a separate pull request for each item.