From 0b2a91a31b726c58935ae2e724029b534989b3eb Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Wed, 5 Apr 2023 08:32:26 +1000 Subject: [PATCH] fix: polyfill fetch in JSDom (#140) * fix: polyfill fetch in JSDom * chore: add fixme --- packages/jest-jsdom-polyfills/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/jest-jsdom-polyfills/index.js b/packages/jest-jsdom-polyfills/index.js index 6cc3c314..ac0d5cef 100644 --- a/packages/jest-jsdom-polyfills/index.js +++ b/packages/jest-jsdom-polyfills/index.js @@ -63,14 +63,17 @@ if (typeof globalThis.File === "undefined") { globalThis.File = stdFile.File; } +// FIXME This is a temporary workaround for https://github.com/jsdom/jsdom/issues/1724#issuecomment-720727999 // The following fetch APIs are missing in JSDom if ( typeof globalThis.Response === "undefined" || typeof globalThis.Request === "undefined" || - typeof globalThis.Headers === "undefined" + typeof globalThis.Headers === "undefined" || + typeof globalThis.fetch === "undefined" ) { - const { Request, Response, Headers } = require("undici"); + const { Request, Response, Headers, fetch } = require("undici"); globalThis.Response = Response; globalThis.Request = Request; globalThis.Headers = Headers; + globalThis.fetch = fetch; }