{"id":19450469,"url":"https://github.com/mswjs/jest-fixed-jsdom","last_synced_at":"2025-04-12T15:37:43.500Z","repository":{"id":228360796,"uuid":"773757720","full_name":"mswjs/jest-fixed-jsdom","owner":"mswjs","description":"A superset of the JSDOM environment for Jest that respects Node.js globals. ","archived":false,"fork":false,"pushed_at":"2024-11-13T09:43:12.000Z","size":73,"stargazers_count":66,"open_issues_count":7,"forks_count":6,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-27T20:11:11.954Z","etag":null,"topics":["environment","jest","jsdom","msw","mswjs","node","testing"],"latest_commit_sha":null,"homepage":"https://npm.im/jest-fixed-jsdom","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mswjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-18T10:49:50.000Z","updated_at":"2025-03-14T05:26:14.000Z","dependencies_parsed_at":"2024-11-10T16:39:02.630Z","dependency_job_id":"6bb3ab29-cc23-47b6-86d8-263078ba19f2","html_url":"https://github.com/mswjs/jest-fixed-jsdom","commit_stats":null,"previous_names":["mswjs/jest-fixed-jsdom"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fjest-fixed-jsdom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fjest-fixed-jsdom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fjest-fixed-jsdom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fjest-fixed-jsdom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mswjs","download_url":"https://codeload.github.com/mswjs/jest-fixed-jsdom/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247078862,"owners_count":20879952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["environment","jest","jsdom","msw","mswjs","node","testing"],"created_at":"2024-11-10T16:37:52.877Z","updated_at":"2025-04-03T21:11:00.088Z","avatar_url":"https://github.com/mswjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003ejest-fixed-jsdom\u003c/h1\u003e\n\u003cp align=\"center\"\u003eA superset of the JSDOM environment for Jest that respects Node.js globals.\u003c/p\u003e\n\n\u003c!-- prettier-ignore-start --\u003e\n\u003e [!WARNING]\n\u003e **This package is never meant as a solution to anything**. This is a workaround. Please consider testing browser code in the actual browser. You can do so both in [Vitest](https://vitest.dev/guide/browser/) and in [Playwright](https://playwright.dev/docs/test-components) at the moment.\n\u003c!-- prettier-ignore-end --\u003e\n\n## Motivation\n\nWhen you use Jest with JSDOM you are getting a broken test environment. Some Node.js globals cease to exist (e.g. `Request`, `Response`, `TextEncoder`, `TextDecoder`, `ReadableStream`\u003csup\u003e\u003ca href=\"https://github.com/mswjs/msw/issues/1916\"\u003e1\u003c/a\u003e\u003c/sup\u003e), while others stop behaving correctly (e.g. `Event`, `MessageEvent`\u003csup\u003e\u003ca href=\"https://github.com/nodejs/undici/issues/2663\"\u003e2\u003c/a\u003e\u003c/sup\u003e, `structuredClone()`\u003csup\u003e\u003ca href=\"https://github.com/mswjs/msw/issues/1931\"\u003e3\u003c/a\u003e\u003c/sup\u003e). That is caused by `jest-environment-jsdom` and JSDOM relying on polyfills to implement standard APIs that have been available globally both in the browser and in Node.js for years.\n\nHere's a piece of valid JavaScript that works in both the browser and Node.js but fails in Jest/JSDOM:\n\n```js\nnew TextEncoder().encode('hello')\n```\n\n```\nReferenceError: TextEncoder is not defined\n```\n\n**We strongly believe that a valid JavaScript code must compile regardless of what test environment you are using**. In fact, having a proper test environment is crucial to get any kind of value from your tests. Jest/JSDOM take that already working environment away from you.\n\nWe've built this project aims to fix that problem, restoring the global APIs that are present in both environments, providing better interoperability, stability, and consistent runtime behavior.\n\n## Changes\n\nThis project \"fixes\" the following global APIs, overriding whichever polyfills they have with respective Node.js globals:\n\n- `fetch()`\n- `Blob`\n- `FormData`\n- `Headers`\n- `Request`\n- `Response`\n- `ReadableStream`\n- `TextEncoder`\n- `TextDecoder`\n- `TextEncoderStream`\n- `TextDecoderStream`\n- `structuredClone()`\n- `URL`\n- `URLSearchParams`\n- `BroadcastChannel`\n- `TransformStream`\n\n## Getting started\n\n### Install\n\n```sh\nnpm i jest-fixed-jsdom --save-dev\n```\n\n### Configure Jest\n\nIn your `jest.config.js`, set the `testEnvironment` option to `jest-fixed-jsdom`:\n\n```js\n// jest.config.js\nmodule.exports = {\n  testEnvironment: 'jest-fixed-jsdom',\n}\n```\n\n\u003e You can use any other `testEnvironmentOptions` you need. Those will be forwarded to the underlying `jest-environment-jsdom`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmswjs%2Fjest-fixed-jsdom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmswjs%2Fjest-fixed-jsdom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmswjs%2Fjest-fixed-jsdom/lists"}