question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getByText() failing in most basic use case, need help

See original GitHub issue

Okay, 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?

image

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
clrndcommented, Jun 8, 2022

I’m having the same issue 🤔, debug() shows the element is there but no ByText query finds it 🤷

3reactions
jim-at-jibbacommented, Apr 26, 2022

Any movement on this. I am experiencing the same. Using the same versions as above.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found