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 install jsdom
yarn add jsdom
pnpm add jsdom
Import
import { JSDOM } from 'jsdom';Quick Example
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
| Package | jsdom |
| Category | Utility |
| Weekly Downloads | 20M+ |
| License | MIT |
| Install | npm install jsdom |
Related Packages
Cheerio is a fast, flexible, and lean implementation of jQuery designed specifically for server-side…
Jest is a delightful JavaScript testing framework with a focus on simplicity, created by Facebook. I…
Testing Library is a family of packages that helps you test UI components in a way that resembles ho…
Puppeteer is a Node.js library developed by Google that provides a high-level API to control Chrome …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.