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.

"Cannot read property 'testID' of null"

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Aleksefocommented, Aug 13, 2021

Happens on version 7.1.0+ Downgrading to version 7.0.2 fixes the issue.

"react": "17.0.1",
"react-native": "0.64.2",
"react-redux": "^7.2.0",
"redux-actions": "^2.6.5"
"@testing-library/jest-native": "^4.0.2",
"@testing-library/react-native": "7.0.2",
"jest": "^26.6.3",
"react-test-renderer": "17.0.1",
"redux-mock-store": "^1.5.4",
1reaction
conor909commented, Jul 23, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property of null in jest test where child ...
I've moved the mock up before importing Parent but now getting this error: Invariant Violation: Element type is invalid: expected a string (for ......
Read more >
Fixing TypeError: Cannot read property `property` of null in ...
Recently, I ran into some problems while attempting to snapshot test my React code. TypeError: Cannot read property 'focus' of null.
Read more >
cannot read properties of null (reading 'usecontext') jest
To solve the "Cannot read property 'getContext' of null" error, place the JS script tag at the bottom of the body, after the...
Read more >
Testing Recipes
Read more details on setting up a testing environment on the Testing ... import { unmountComponentAtNode } from "react-dom"; let container = null; ......
Read more >
Testing Components – Testing Angular
Components are the power houses of an Angular application. ... A test id is an identifier given to an element just for the...
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