So I am writing unit test using “react-testing-library” on Jest and I have this error:
Test suite failed to run ReferenceError: global is not defined at Object.<anonymous> (node_modules/@jest/core/node_modules/graceful-fs/graceful-fs.js:92:1) at Object.<anonymous> (node_modules/@jest/core/node_modules/expect/build/toThrowMatchers.js:10:24) at Object.<anonymous> (node_modules/@jest/core/node_modules/expect/build/index.js:35:48) at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13) at runJest (node_modules/@jest/core/build/runJest.js:387:19) at _run10000 (node_modules/@jest/core/build/cli/index.js:408:7) at runCLI (node_modules/@jest/core/build/cli/index.js:261:3)
Advertisement
Answer
After I added "jest-environment-jsdom": "^27.0.6"
as a dev dependency, that error went away.