getByText() failing in most basic use case, need help
See original GitHub issueOkay, so I’m brand new to react-native-testing as of this morning and have not been able to do something as simple as do getByText()
. So, I’m not going to claim this issue is a bug with the library, but a “bug” with my basic understanding of how to use it. Please help me see what I’m missing? Thanks.
Given this jest test file in my React Native 0.67.2 app:
import React from 'react';
import { Text } from 'react-native';
import { cleanup, render, RenderAPI } from '@testing-library/react-native';
describe('react-native-test example', () => {
let c: RenderAPI;
beforeEach(() => {
c = render(<Text>example</Text>);
});
afterEach(cleanup);
test('getByText()', () => {
c.debug();
expect(c.getByText('example')).toBeDefined();
});
});
Why do I get this result?
I also tried <Text>{'example'}</Text>
and getByText(/example/)
to no avail.
Versions:
"react": "~17.0.2",
"@testing-library/jest-native": "^4.0.4",
"@testing-library/react-native": "^9.0.0",
"jest": "^25.1.0",
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (5 by maintainers)
Top Results From Across the Web
How to expect a getByText to be false in react testing library?
Another good approach would be to wait for your open modal, something like: describe('modal component', () => { test('should not be ...
Read more >About Queries | Testing Library
getBy... : Returns the matching node for a query, and throw a descriptive error if no elements match or if more than one...
Read more >Making sure you're using the correct query - Tim Deschryver
getByText (/login/i, { selector: 'button' });. For this simple case, this approach is OK. But this could cause problems if CSS classes are...
Read more >Fix Your Failing Tests: A Debugging Checklist for React ...
Solutions to the most common React testing issues. ... In this case, you can provide a function for your text matcher to make...
Read more >Common mistakes with React Testing Library - Kent C. Dodds
Advice : Install and use the ESLint plugin for Testing Library. ... (supported for most major testing frameworks) and you no longer need...
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
I’m having the same issue 🤔,
debug()
shows the element is there but noByText
query finds it 🤷Any movement on this. I am experiencing the same. Using the same versions as above.