Skip to content

Commit

Permalink
fix: polyfill fetch in JSDom (#140)
Browse files Browse the repository at this point in the history
* fix: polyfill fetch in JSDom

* chore: add fixme
  • Loading branch information
jeswr authored Apr 4, 2023
1 parent 0eb35d0 commit 0b2a91a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/jest-jsdom-polyfills/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 0b2a91a

Please sign in to comment.