Skip to content

React test with typescript throws TypeError: Cannot read properties of undefined (reading 'S') #1370

@ahuigo

Description

@ahuigo

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
image

Reproduced code on github:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions