Next.js 12 introduced next/jest
, an experimental jest transformer that integrates swc/jest
with little config. Problems can be added to the respective discussion.
This repo is here to reproduce some issues.
As some others reported, next/jest
has problems with Jest's mocking.
In addition, I found no way to temporarily delete the window
object to simulate an SSR environment. Admittedly, it does require a decent amount of gymnastics to get working in the first place. Handy non the less.
There are different ways to set window
to undefined
. None worked. Be it deleting it, nor messing with jests mocking.
Changing Jest's environment to node
using docblocks also doesn't solve our problems.
# install
yarn
# run tests
yarn test
Three commits on total.
- setup
jest/swc
(broken)babel-jest
(works)
Check out commit #2 or #3 to verify.