Cannot read properties of undefined (reading 'current')
See original GitHub issue@testing-library/react-hooksversion:7.0.2reactversion:18.0.0-alpha-5ca4b0433-20211020react-domversion (if applicable):18.0.0-alpha-5ca4b0433-20211020react-test-rendererversion (if applicable):17.0.1nodeversion:16.13.0npm(oryarn) version: yarn version => 1.22.15typescriptversion: ~4.4
Relevant code or config:
import { renderHook } from "@testing-library/react-hooks"
function useTest() {
return { res: true }
}
describe('useTest', () => {
it('should render', () => {
const { result } = renderHook(() => useTest());
});
});
What you did:
This is part of a Blitz.js app. This is a very minimal example. I started testing a more complex custom hook and i got in first place TypeError: Cannot read properties of undefined (reading ‘current’) so i decided to tear down to a bare minimal example.
What happened:
yarn test --verbose -t "useTest"
yarn run v1.22.15
$ jest --verbose -t useTest
FAIL CLIENT app/githubs/hooks/useQueryBuilder.hook.test.ts
useTest
✕ should render (7 ms)
● useTest › should render
TypeError: Cannot read properties of undefined (reading 'current')
7 | describe('useTest', () => {
8 | it('should render', () => {
> 9 | const { result } = renderHook(() => useTest());
| ^
10 | });
11 | });
12 |
at act (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:15259:59)
at renderHook (node_modules/@testing-library/react-hooks/lib/pure.js:148:30)
at Object.<anonymous> (app/githubs/hooks/useQueryBuilder.hook.test.ts:9:28)
Test Suites: 1 failed, 5 skipped, 1 of 6 total
Tests: 1 failed, 20 skipped, 21 total
Reproduction:
Problem description:
Blitz.js comes with @testing-library/react-hooks:4.0.1 so i upgraded to 7.0.2 but nothing change.
Suggested solution:
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
TypeError: Cannot read properties of undefined (reading 'and')
It keeps failing with this error in Karma. TypeError: Cannot read properties of undefined (reading 'and') import { ComponentFixture, TestBed } ...
Read more >I need help. TypeError: Cannot read ... - DEV Community
I need help. TypeError: Cannot read properties of undefined (reading 'current'). This is code ⬇️⬇️. function QuizLogic(showScore, totalTime ...
Read more >[SOLVED] Cannot Read Property of Undefined in JavaScript
The “cannot read property of undefined” error occurs when you attempt to access a property or method of a variable that is undefined...
Read more >Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >Uncaught TypeError: Cannot read property of undefined In
This error occurs in Chrome Browser when you read a property or call a method on an undefined object . There are a...
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 Free
Top 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
renderHookAPI fromreact-testing-library(see here for details)react-test-rendererto react 18 as well (the stack trace points to that as the detected renderer, but you are postingreact-domversions). Please see our docs about targeting specific renderers if you intend to usereact-domgoing forward.I have a same problem.
(my react version is 18.1.0)
so I upgraded “react-test-renderer” 17.0.2 to 18.1.0 and it works!