🛠️
Utility20M+/wkMIT

jsdom

jsdom is a pure JavaScript implementation of web standards, primarily the WHATWG DOM and HTML Standards, for use with Node.js. It creates a simulated browser en

Installation

npm
npm install jsdom
yarn
yarn add jsdom
pnpm
pnpm add jsdom

Import

ESM
import { JSDOM } from 'jsdom';

Quick Example

usage
import { JSDOM } from 'jsdom';

const dom = new JSDOM('<p>Hello world</p>');
const doc = dom.window.document;

console.log(doc.querySelector('p').textContent);
// 'Hello world'

About jsdom

jsdom is a pure JavaScript implementation of web standards, primarily the WHATWG DOM and HTML Standards, for use with Node.js. It creates a simulated browser environment complete with a window object, document, DOM APIs, event handling, form submission, navigation, and many other web platform features — all without an actual browser engine. jsdom is essential for testing browser-dependent code in Node.js environments, serving as the default DOM implementation for Jest's test environment (jest-environment-jsdom). The library handles HTML parsing, CSS selector matching, cookie management, XMLHttpRequest, fetch API emulation, local and session storage, and custom element support. jsdom can load external resources including scripts and stylesheets, execute embedded JavaScript, and simulate user events. The library configures pretend URLs, referrers, user agents, and content types, making it suitable for testing code that depends on location.href, document.cookie, or navigator properties. While jsdom does not implement a layout engine (no CSS layout calculations, no visual rendering), it provides sufficient DOM fidelity for testing most web application logic, component rendering, and event handling patterns.

Quick Facts

Packagejsdom
CategoryUtility
Weekly Downloads20M+
LicenseMIT
Installnpm install jsdom

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.