-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed as not planned
Labels
Description
Version
29.4.1
Steps to reproduce
- Clone my repo at https://github.com/hahanein/no-fetch-api-in-jsdom-environment
- pnpm i
- pnpm test
- You should see the error "ReferenceError: fetch is not defined"
Expected behavior
I expect to see the following results:
PASS ./script.test.js
✓ testing fetch (670 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Actual behavior
The test is failing with the error message "ReferenceError: fetch is not defined".
However, when you remove the line testEnvironment: 'jsdom'
from jest.config.js
everything is working as expected.
Additional context
Due to this behavior we are forced to polyfill the Fetch API (fetch
, Response
, Request
, ...) at my workplace. This is becoming progressively more tedious. node-fetch/node-fetch#1263
Environment
System:
OS: Linux 6.1 Arch Linux
CPU: (8) x64 AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx
Binaries:
Node: 19.4.0 - /usr/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 8.19.2 - /usr/bin/npm
npmPackages:
jest: ^29.4.1 => 29.4.1