React test with typescript throws `TypeError: Cannot read properties of undefined (reading 'S')`
ahuigo opened this issue · 1 comments
ahuigo commented
issue
React test with typescript throws error
$ npm test
TypeError: Cannot read properties of undefined (reading 'S')
1 | import * as React from 'react';
2 | import '@testing-library/jest-dom';
> 3 | import { render, fireEvent } from '@testing-library/react';
| ^
4 | import { Hello } from './Hello';
Package version
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^22.1.0",
"@types/react": "^18.3.14",
"@types/react-dom": "^19.0.1",
"jest": "^28.1.1",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^28.0.4",
"ts-node": "^10.9.2",
"typescript": "^4.9.0"
Reproduced code
sandbox cases:
https://codesandbox.io/p/sandbox/react-test-ts-3q4lr6

Reproduced code on github:
https://github.com/ahuigo/react-ts-test-demo/blob/main/src/Hello.test.tsx

MatanBobi commented
Hi @ahuigo.
You're using different versions for React and React-DOM, this is not possible.
Upgrading your React version to 19 and installing @testing-library/dom resolved the issue.
https://codesandbox.io/p/sandbox/react-test-ts-forked-3h2zkm?workspaceId=ws_SnEjMZgyHMRRBkFgUp3JGk