Skip to content

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

Closed
@jkoutavas

Description

@jkoutavas

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",

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions