react-testing-library icon indicating copy to clipboard operation
react-testing-library copied to clipboard

ReactElement not assignable

Open AhmedHadjTaieb opened this issue 1 year ago • 3 comments

Hello,

I am using Next.js, and I have a problem when trying to test a component with react.createNode or react.createElement. The test cannot understand my component and displays errors. However, on all other components that do not use these features, the tests work fine. My environment:

"next": "14.0.1", "typescript": "5.2.2", "react": "18.2.0", "react-dom": "18.2.0", "@testing-library/jest-dom": "5.16.5" "@testing-library/react": "14.1.2", "@types/react": "18.2.14", "@types/react-dom": "18.2.6", "jest-environment-jsdom": "29.3.1", "ts-jest": "29.1.0",

What I did:

Capture d’écran 2024-01-29 à 09 58 46 (2)

Capture d’écran 2024-01-29 à 09 57 30

Problem description:

Argument of type 'boolean' is not assignable to parameter of type 'ReactElement<any, string | JSXElementConstructor>'.ts(2345) Parsing error: '>' expected.eslint 'ListPageActionBar' refers to a value, but is being used as a type here. Did you mean 'typeof ListPageActionBar'?

AhmedHadjTaieb avatar Jan 29 '24 09:01 AhmedHadjTaieb

Looks like you're using a .ts file not a .tsx file. Can you provide a cloneable repro or, ideally, a TypeScript playground?

eps1lon avatar Jan 29 '24 16:01 eps1lon

It's a .tsx file, not .ts. As for the report, it may not be possible; perhaps we need to create another project with the same configuration, but that will take some time.

AhmedHadjTaieb avatar Jan 30 '24 12:01 AhmedHadjTaieb

It's likely an editor misconfiguration. It parses the file as ts not tsx hence the "Parsing error: '>' expected".

eps1lon avatar Jan 30 '24 18:01 eps1lon