"Cannot read property 'testID' of null"
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:8 (2 by maintainers)
Top 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 >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
Happens on version 7.1.0+ Downgrading to version 7.0.2 fixes the issue.
Would this be related to my question? https://github.com/callstack/react-native-testing-library/issues/786