Closed mike-lischke closed 1 year ago
Well, it's actually a problem with Jest, which uses React for running tests. The solution for the above problem is to map the React calls to preact, like:
moduleNameMapper: {
'^react/jsx-runtime$': 'preact/jsx-runtime',
},
in jest.config.js or package.json. It's not clear to me why any React runtime call would be used without this mapping, given that I have no React installed.
Describe the bug
In a big application we switched from CRA to preact with vite. The app runs fine and now I want to fix the unit tests. However, I keep getting the error mentioned in the title when I run a render test like this:
The
shallow
call throws the error (which I know comes fromenzyme
), but I debugged it down to preact code. More precisely it happens in preact.module.js. I only have the node module at hand, so I don't know to which source file this error location corresponds. It's line 102 in the latest code:I believe it's the first assignment. Here are the values:
To Reproduce
I would love to give you a simple example for this problem, but this is a big project and I'm not yet done with fixing things, let alone extracting something from it to show a simple case.
All I do is to run this single test case.
Expected behavior
No error. The test should succeed as it did before I started converting the entire app. For completeness here's my jest config:
and my project dependencies: