API Reference

jsdom

A pure-JavaScript implementation of web standards that lets you run DOM scripts in Node.js tests.

Official Documentation ↗
CompatibilityThis documentation covers version v30.1.3. Check the official docs for the latest API surface.

Installation

npmnpm install jsdom

Methods

jsdom provides window, document, and many web APIs in Node so front-end code can be exercised without a browser.

Key Features

  • DOM traversal and mutation
  • Optional script execution with runScripts
  • Works as a Vitest/Jest test environment

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/jsdom/jsdom@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:34.150Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/jsdom/jsdom@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:34.150Z.

FAQ

Is jsdom a browser?
No. It implements DOM and many web APIs but does not render or run a full layout engine, so visual tests are out of scope.
Why does my test hang after using jsdom?
Timers and requests created in the window keep the event loop alive. Call dom.window.close() in teardown to release them.
Can I load external scripts?
Yes with resources: "usable" and runScripts: "dangerously", but never do that on untrusted HTML because scripts run with Node privileges.