Monday, June 3, 2024
184
rated 0 times [  190] [ 6]  / answers: 1 / hits: 16180  / 3 Years ago, wed, july 7, 2021, 12:00:00

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)

More From » unit-testing

 Answers
27

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


[#50241] Saturday, June 5, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lelasamiraa

Total Points: 208
Total Questions: 99
Total Answers: 107

Location: Uzbekistan
Member since Tue, Nov 30, 2021
3 Years ago
lelasamiraa questions
Thu, Jul 16, 20, 00:00, 4 Years ago
Thu, Oct 17, 19, 00:00, 5 Years ago
Mon, Aug 5, 19, 00:00, 5 Years ago
Thu, Feb 7, 19, 00:00, 5 Years ago
;