document is not defined #28337
-
What version of Next.js are you using?11.1 What version of Node.js are you using?16.4.2 What browser are you using?Chrome 92 What operating system are you using?macOS 11.5.2 How are you deploying your application?Vercel Describe the BugSince updating to NextJS 11.1, I am unable to run any tests. The error I get is: Here is my Jest config: Which matches the documentation: https://nextjs.org/docs/testing, its just in my Expected BehaviorIt run the tests correctly. To ReproduceCreate a new NextJS 11.1 project. Add the above Jest config to your package.json. Create a new component and test, something similar to this: Run the test, it should fail. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @Dalez! Thank you for reporting this, I appreciate it. It raised a gap in our docs and example caused by my oversight: I didn't update our example to the latest Jest which changed the default testing environment from You can solve the error by changing the testing environment to /**
* @jest-environment jsdom
*/You can also configure the I will update the example and testing docs accordingly. |
Beta Was this translation helpful? Give feedback.
Hi @Dalez! Thank you for reporting this, I appreciate it. It raised a gap in our docs and example caused by my oversight: I didn't update our example to the latest Jest which changed the default testing environment from
jsdomtonode.@testing-library/reactrequires ajsdomenvironment because it makes use of DOM elements likedocument.body.You can solve the error by changing the testing environment to
jsdomby adding the following comment to any test files that use@testing-library/reactYou can also configure the
jsdomenvironment globally by updating the JesttestEnvironmentconfiguration option but it's not recommended.I will update the example and…