In your package.json, or jest.config.js/jest.config.ts file, change the value of the testEnvironment property to jsdom.

package.json

"jest":{
    "testEnvironment": "jsdom"
}

jest.config.[js|ts]

module.exports = {
    "testEnvironment": "jsdom"
}

Important note for jest >28

If you are using jest 28, you will need to install jest-environment-jsdom separately by either:

npm: npm i jest-environment-jsdom --save-dev

yarn: yarn add -D jest-environment-jsdom

Why?

By default, jest uses the node testEnvironment. This essentially makes any tests meant for a browser environment invalid.

jsdom is an implementation of a browser environment, which supports these types of UI tests.

For Jest version 28 and greater, jest-environment-jsdom was removed from the default jest installation to reduce package size.

Additional reading

jest testEnvironment documentation

Jest 28 breaking changes

Answer from Moistbobo on Stack Overflow
Top answer
1 of 4
222

In your package.json, or jest.config.js/jest.config.ts file, change the value of the testEnvironment property to jsdom.

package.json

"jest":{
    "testEnvironment": "jsdom"
}

jest.config.[js|ts]

module.exports = {
    "testEnvironment": "jsdom"
}

Important note for jest >28

If you are using jest 28, you will need to install jest-environment-jsdom separately by either:

npm: npm i jest-environment-jsdom --save-dev

yarn: yarn add -D jest-environment-jsdom

Why?

By default, jest uses the node testEnvironment. This essentially makes any tests meant for a browser environment invalid.

jsdom is an implementation of a browser environment, which supports these types of UI tests.

For Jest version 28 and greater, jest-environment-jsdom was removed from the default jest installation to reduce package size.

Additional reading

jest testEnvironment documentation

Jest 28 breaking changes

2 of 4
29

This can be solved on a per-test-file basis by adding a @jest-environment docblock to the beginning of your file. For example:

/** @jest-environment jsdom */
import React from 'react'
import { render } from '@testing-library/react'

import Button from '.'

describe('Button', () => {
  it('renders button without crashing', () => {
    const label = 'test'

    render(<Button label={label} />)
  })
})

If your project has a mix of UI and non-UI files, this is often preferable to changing the entire project by setting "testEnvironment": "jsdom" within your package.json or Jest config. By skipping initializing the JSDom environment for non-UI tests, Jest can run your tests faster. In fact, that's why Jest changed the default test environment in Jest 27.

🌐
npm
npmjs.com › package › jest-environment-jsdom
jest-environment-jsdom - npm
March 10, 2026 - Latest version: 30.3.0, last published: 2 months ago. Start using jest-environment-jsdom in your project by running `npm i jest-environment-jsdom`. There are 1454 other projects in the npm registry using jest-environment-jsdom.
      » npm install jest-environment-jsdom
    
Published   Mar 10, 2026
Version   30.3.0
🌐
Jest
jestjs.io › configuring jest
Configuring Jest · Jest
jest-environment-jsdom defaults to ['browser']. jest-environment-node defaults to ['node', 'node-addons'].
🌐
Jest
jestjs.io › dom manipulation
DOM Manipulation · Jest
October 26, 2023 - Also, the function being tested adds an event listener on the #button DOM element, so we need to set up our DOM correctly for the test. jsdom and the jest-environment-jsdom package simulate a DOM environment as if you were in the browser.
🌐
Testing Library
testing-library.com › setup
Setup | Testing Library
October 29, 2023 - If you're running your tests in the browser bundled with webpack (or similar) then DOM Testing Library should work out of the box for you. However, most people using DOM Testing Library are using it with the Jest testing framework with the testEnvironment set to jest-environment-jsdom
🌐
GitHub
github.com › bufbuild › jest-environment-jsdom
GitHub - bufbuild/jest-environment-jsdom: A modern jsdom test environment for Jest · GitHub
@bufbuild/jest-environment-jsdom: Jest test environment with support for the Encoding API.
Author   bufbuild
🌐
GitHub
github.com › mswjs › jest-fixed-jsdom
GitHub - mswjs/jest-fixed-jsdom: A superset of the JSDOM environment for Jest that respects Node.js globals. · GitHub
A superset of the JSDOM environment for Jest that respects Node.js globals. - mswjs/jest-fixed-jsdom
Starred by 94 users
Forked by 9 users
Languages   JavaScript
🌐
Epic Web Dev
epicweb.dev › why-i-won-t-use-jsdom
Why I Won’t Use JSDOM | Epic Web Dev
January 28, 2025 - Those environments have improved a bit since then, but, sadly, the issue sits too deep to be eradicated in any refactor. One of my favorite examples of this is the support of the Fetch API in JSDOM, which took years of constant polyfilling even after the API has landed in Node.js in 2017. You couldn’t use global fetch in your tests until recently without getting the fetch is not defined error in Jest for a standard API that’s been around for almost two decades.
🌐
Manning
freecontent.manning.com › home › testing with node, jest, and jsdom
Testing with Node, Jest, and JSDOM - Manning
January 29, 2021 - To be able to run your tests in Jest, instead of running your tests within the browser, you can bring browser APIs to Node by using JSDOM. You can think of JSDOM as an implementation of the browser environment which can run within Node. It ...
Find elsewhere
🌐
GitHub
github.com › simon360 › jest-environment-jsdom-global › blob › main › README.md
jest-environment-jsdom-global/README.md at main · simon360/jest-environment-jsdom-global
Similar to the standard jest-environment-jsdom, but exposes jsdom so that you can reconfigure it from your test suites.
Author   simon360
🌐
Ken Muse
kenmuse.com › blog › crash-course-jest-test-environments-with-typescript
A Crash Course on Jest TestEnvironments with TypeScript - Ken Muse
August 24, 2024 - Essentially, it’s a module that can be used to setup the test environment that is used for executing the tests. Out of the box, it defaults to node, but offers jsdom for web testing. Essentially, it’s just a module that exports a class with a few methods that Jest will call at various points in the test lifecycle.
🌐
npm
npmjs.com › package › jest-environment-jsdom-global
jest-environment-jsdom-global - npm
August 30, 2022 - Similar to the standard jest-environment-jsdom, but exposes jsdom so that you can reconfigure it from your test suites.
      » npm install jest-environment-jsdom-global
    
Published   Aug 30, 2022
Version   4.0.0
🌐
Medium
medium.com › @jelena.durovic › how-to-configure-jest-with-typescript-fe034ad7d6c2
How to configure Jest with TypeScript | by Jelena Durovic | Medium
May 17, 2022 - By default, jest uses the node testEnvironment. This essentially makes any tests meant for a browser environment invalid. jsdom is an implementation of a browser environment, which supports these types of UI tests.
🌐
GitHub
gist.github.com › thebuilder › 15a084f74b1c6a1f163fc6254ad5a5ba
Use Jest Projects to run both JSDom and Node tests in the same project · GitHub
Just use jest like you normally to run the tests. ... Thanks for this. ... This got me on the right track, thank you! In my case I was missing another piece: I have a unified project with both client/ and server/ code, each with their own package.json. I had to set "type": "module" in the package.json corresponding to the client (with jsdom environment) tests.
🌐
DEV Community
dev.to › htho › updating-to-jest-30-is-frustrating-its-jsdom-2jn3
Updating to Jest 30 is Frustrating (it's JSDOM) - DEV Community
November 10, 2025 - I wanted to be clever and thought we might manipulate the JSDOM Window Object with Proxies and apply them using @jest/environment-jsdom-abstract - but I was wrong....
🌐
DEV Community
dev.to › konnorrogers › why-jest-is-not-for-me-46c5
Why Jest is not for me - DEV Community
October 27, 2021 - This lets us enable fast iteration speed and prevent flakiness. While Jest provides browser globals such as window thanks to jsdom, they are only approximations of the real browser behavior.
🌐
npm
npmjs.com › search
jsdom - npm search
A superset of the JSDOM environment for Jest that respects Node.js globals.