jsdom
A pure-JavaScript implementation of web standards that lets you run DOM scripts in Node.js tests.
Official Documentation ↗v30.1.3. Check the official docs for the latest API surface.Installation
npm install jsdomMethods
No methods match this filter.
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.
- Values that are not a HTML MIME type or an XML MIME type will throw. (https://cdn.jsdelivr.net/gh/jsdom/jsdom@latest/README.md)
- This includes both jsdom output (such as not-implemented warnings or CSS parsing errors) and in-page window.console calls. (https://cdn.jsdelivr.net/gh/jsdom/jsdom@latest/README.md)
- Note that this method will throw an exception if the JSDOM instance was created without runScripts set. (https://cdn.jsdelivr.net/gh/jsdom/jsdom@latest/README.md)
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.
- If you use it on arbitrary user-supplied code, or code from the Internet, you are effectively running untrusted Node.js code, and your machine could be compromised. (https://cdn.jsdelivr.net/gh/jsdom/jsdom@latest/README.md)
- Tidelift helps making open source sustainable for us while giving teams assurances for maintenance, licensing, and security. (https://cdn.jsdelivr.net/gh/jsdom/jsdom@latest/README.md)
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.