Closed josuevalrob closed 1 year ago
@josuevalrob, are you using jsdom
as Jest environment?
Since newer versions of Jest, its default environment is node
now. You need to explicitly install and use jest-environment-jsdom
to run browser-like code:
npm i jest-environment-jsdom -D
// your.test.js
/**
* @jest-environment jsdom
*/
Then XMLHttpRequest
will be globally defined by the environment.
The error right now happens not because of third-party libraries but because your testing environment doesn't know what XMLHttpRequest
is.
I can also see some interesting jest.config.js
setup that I've never seen before. I don't think you can use async functions to create Jest config. It must be a plain object.
This should be fixed with the new examples. Please give them a try!
Test:
The feature:
Server configuration
The error
Why am i importing
XMLHttpRequest
library:ReferenceError: XMLHttpRequest is not defined
What could be the issue?