Closed dianyuyi closed 2 years ago
Hey there
This looks like a duplicate of #697, could you please confirm if that fixes the issue here?
Thank you very much. The error was successfully fixed.
The origin setup is
transform: { '^.+\\.(js|jsx|ts|tsx)$': [ 'babel-jest', 'babel-plugin-styled-components', { presets: ['next/babel'] }, ], }
Then replace to below will work
transform: { '^.+\\.(js|jsx|ts|tsx|mjs)$': 'babel-jest', }
Not sure why the original project was set up like this, but I think it tells us that sometimes simplicity is best...
Describe
When I test the component with jest, it returns an error. I'm using Nextjs to build my project, and structure just like
This is my test file in
src/components/blocks/home
And It will return
I try to replace
to
Then return another error
finally, when I replace code to
...it works. But I can't do this because that means the styled components of the whole project have to be rewritten.
Configs check
I checked all configs and try to fix them, but no method works. My configs below
Related packages
tsconfig.json
jest.config
jest.setup.ts
.babelrc.js
I tried to change all the settings that might cause the error but in vain. Can anyone help me, please?