Skip to content

"Cannot read property 'testID' of null" #785

@milesj

Description

@milesj

Describe the bug

Currently in the process of upgrading RN to v0.64 and RNTL to v8-rc.0. After upgrading RNTL, many tests started throwing errors similar to the following:

TypeError: Cannot read property 'testID' of null
--
  |  
  | at getNodeByTestId (node_modules/@testing-library/react-native/build/helpers/byTestId.js:11:61)
  | at node_modules/@testing-library/react-native/build/helpers/byTestId.js:15:44
TypeError: Cannot read property 'testID' of nullError: Cannot read property 'testID' of null
--
  |  
  | 83 \|   delayed = false,
  | 84 \| ) => {
  | > 85 \|   await waitFor(async () => {
  | \|         ^
  | 86 \|     await cb();
  | 87 \|
  | 88 \|     // Ensure an additional tick has fired, otherwise the act would close before
  |  
  | at _callee4$ (src/support/testHelpers.tsx:85:9)
TypeError: Cannot read property 'testID' of nullError: Cannot read property 'testID' of null
--
  |  
  | 571 \|
  | 572 \|       it('renders the preview button', async () => {
  | > 573 \|         await waitFor(() => renderResult.queryByTestId('PreviewButton'));
  | \|               ^
  | 574 \|         expect(renderResult.queryByTestId('PreviewButton')).toBeTruthy();
  | 575 \|       });
  | 576 \|

Expected behavior

It doesn't throw.

Steps to Reproduce

Honestly, I have no idea why this is happening (all the tests look correct), or if the RNTL upgrade is the cause.

But I figured I would report this issue in case others are running into the same problem.

Screenshots

Versions

  npmPackages:
    @testing-library/react-native: 8.0.0-rc.1 => 8.0.0-rc.1
    react: 17.0.2 => 17.0.2
    react-native: 0.64.2 => 0.64.2
    react-test-renderer: 17.0.2 => 17.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions