Open amannn opened 1 year ago
will this work for you? https://github.com/amannn/jest-globals-bug/pull/1
Hi @SamRoehrich and thanks for participating! In your PR you've deactivated next/jest
. I also noticed that this is a workaround but it kind of defeats the purpose, because I'd like to use next/jest
for the features it provides.
Oh, I did not think that I deactivated it. I was using these docs as reference on how to initialize it. https://github.com/vercel/next.js/blob/canary/examples/with-jest/jest.config.js
I'm running into this bug too. @amannn were you able to find a solution?
Nope, but haven't checked in a while!
Hi. Please read this topic https://github.com/swc-project/swc/discussions/5151. As I understand there are several ways to fix it:
@jest/globals
importsbabel
instead of swc
module.type
commonjs
For anyone facing this issue and confused.
Do not use @jest/globals
means:
use @types/jest as described as the alternative method in https://jestjs.io/docs/getting-started#type-definitions @jest/globals does not work for some reason that might be related to swc, @types/jest works without issues.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Jest (next/jest)
Link to the code that reproduces this issue
https://github.com/amannn/jest-globals-bug
To Reproduce
yarn install && yarn test
Describe the Bug
Jest mocks are not working when using
next/jest
and@jest/globals
. They are ignored.Possible workarounds:
jest
from@jest/globals
(i.e. rely on a global)next/jest
Expected Behavior
Mocks should be applied.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response