Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest: ReferenceError: global is not defined

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)
like image 834
Aman Singh Avatar asked Jul 07 '21 00:07

Aman Singh


Video Answer


1 Answers

After I added "jest-environment-jsdom": "^27.0.6" as a dev dependency, that error went away.

like image 152
dompuiu Avatar answered Nov 15 '22 20:11

dompuiu