@testing-library/react-hooks version: 2.0.1react-test-renderer version: 16.8.6react version: 16.8.6node version: v12.9.0npm version: 6.10.2import { renderHook } from '@testing-library/react-hooks';
import { useMyHook } from '../useMyHook';
test('useMyHook initializes correctly', () => {
const { result } = renderHook(() => useMyHook());
});
simply run the tests react-scripts test --env=jsdom --watchAll
It throw an error saying it can not read property 'current'. I searched most places and I didn't see anyone else getting the same error.
TypeError: Cannot read property 'current' of undefined
12 | test('useMyHook initializes correctly', () => {
> 13 | const { result } = renderHook(() => useMyHook());
^
https://codesandbox.io/s/kind-agnesi-v9ren
Because it doesn't seem to be possible to test hooks with this library.
Is there something missing in the docs that needs to be done as an extra step?
The sandbox you linked has misatching versions for react, react-dom and react-test-renderer.
Updating them all to 16.9.0 makes the test pass. https://codesandbox.io/s/lively-moon-05d78
thanks @mpeyper. can confirm
was seeing error with:
"react": "^16.6.1",
"react-test-renderer": "^16.8.6",
"@testing-library/react": "^9.1.3",
"react-dom": "^16.6.1",
no longer with:
"react": "^16.9.0",
"react-test-renderer": "^16.9.0",
"@testing-library/react": "^9.1.3",
"react-dom": "^16.9.0",
make sure to install the same verions of react and react-test-renderer (e.g. 16.8.3).
Most helpful comment
The sandbox you linked has misatching versions for
react,react-domandreact-test-renderer.Updating them all to
16.9.0makes the test pass. https://codesandbox.io/s/lively-moon-05d78