getByText can't find <Text>
See original GitHub issueDescribe the bug
I’m trying the most basic example possible of getByText
query in a component that just renders one <Text>
component. It can’t find the element.
Expected behavior
It finds the element.
Steps to Reproduce
Create an empty component that just renders <Text>text</Text>
and test with getByText(/text/i)
.
Screenshots
Versions
npmPackages:
@testing-library/react-native: ^7.1.0 => 7.1.0
react: 16.13.1 => 16.13.1
react-native: 0.63.4 => 0.63.4
react-test-renderer: ^16.13 => 16.14.0
Extra info
Maybe it has to do with the way I setup the project? you can find the repository here: https://gitlab.com/joanca/rn-playground
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
getByText doesn't find element with the text - Stack Overflow
As the react-native testing library shows in the documentation examples the getByText query, if provided a string, will look for the exact ...
Read more >ByText - Testing Library
This will search for all elements that have a text node with textContent matching the given TextMatch . <a href="/about"> ...
Read more >Queries | React Native Testing Library - Open Source
Returns a ReactTestInstance with matching text – may be a string or regular expression. This method will join <Text> siblings to find matches,...
Read more >Making sure you're using the correct query - Tim Deschryver
getByText (/hello world/i);. // |>Error: TestingLibraryElementError: Unable to find an element with the text: /hello world/i. This could ...
Read more >Testing Visible Text with React Testing Library's getByText ...
You'll notice that I didn't expect on our total here, and that's because screen.getByText will actually throw an error if it doesn't exist....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
bump
This is a real pain point for someone trying to upgrade from 6.0 as partial matches were working just fine on previous versions.
@lukewlms I think your second example does not work because the queries try to find a perfect match for the text, finding substrings does not work yet. I you have “2MR Plus +” in your component but search for “2MR Plus”, it won’t find the node. However I don’t know how you can search for a font awesome icon in your test. This open PR should help solve your problem by allowing to search for partial match.