Fixed an issue where xByText would call toString() on objects and only match on [object Object]
#290
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This fixes the problem as described in testing-library/native-testing-library#121. In short,
getByText
andqueryByText
would not find a match when the<Text>
component has a nested component inside of it. This was caused by callingtoString()
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
andnumber
-- are there other data types that should be included)?