All Node.js globals
If you are using the new fetch
implementation in Node v18, you might have noticed that this function is not available in Jest. It has been a long-standing issue that we have to manually copy over any globals into the test globals. With Jest 28, this is no longer an issue as we now inspect the global environment Jest itself is running in, and copy over any globals that are missing in the test environment.
Using globalThis
Internally, Jest has been using global
to refer to the global environment. However, since this only exists in Node, and not browsers (window), this led to incompatibility when attempting to use Jest’s modules in another environment.
Jest 28 uses globalThis
instead, which works in all environments.