Skip to content

Fixed an issue where xByText would call toString() on objects and only match on [object Object] #290

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

Merged
merged 1 commit into from
May 1, 2020

Conversation

Vannevelj
Copy link
Contributor

Summary

This fixes the problem as described in testing-library/native-testing-library#121. In short, getByText and queryByText would not find a match when the <Text> component has a nested component inside of it. This was caused by calling toString() on all components it found, meaning something like an <Image> would result in [object Object].

A workaround would be to use a regex match for your text instead so you could decide that that is better than this proposed fix, although I would recommend detailing that somewhere as this isn't easy to debug.

Test plan

I've provided a few unit tests and made sure the code supports a scenario in an existing unit test. That being said, I'm not 100% confident that this change will behave as intended for all scenarios (i.e. we now explicitly take care of string and number -- are there other data types that should be included)?

@thymikee thymikee requested a review from Trancever April 29, 2020 06:36
@thymikee
Copy link
Member

Is this anyhow related to #275?

@Vannevelj
Copy link
Contributor Author

It's related but not the same. The issue I describe here works on a single level, the direct children: with this fix, the Text node and it's siblings are getting an improved string representation.

The issue described there works on descendants. If you want to fix that, you'd need to go down in the component tree and form a string representation of all components in it.

The big difference is that I consider a nested component as an empty string whereas in order to fix that issue, you would need to go into the nested component (recursively) and build up a string representation.

I thought it best to keep the change contained to one issue at first but it shouldn't be terribly hard to expand for his scenario. I wasn't quite sure either what the desired functionality was there so I didn't attempt to fix it.

@thymikee thymikee requested review from Esemesek and cross19xx and removed request for Trancever April 29, 2020 07:04
@thymikee thymikee merged commit 83b28b2 into callstack:master May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants