Happy DOM implements a web browser DOM in JavaScript without a graphical UI. It supports custom elements, Fetch, and common frameworks used in unit and integration tests.
Overview
Happy DOM is a JavaScript and TypeScript implementation of browser document APIs aimed at environments such as Node.js, Bun, and Vitest or Jest test runners. It provides a DOM tree and related standards pieces so UI code can run outside a real browser when a full Chromium or WebKit stack is unnecessary.
Documented DOM features include custom elements and web components, declarative shadow DOM, mutation observers, tree walkers, and the Fetch API. The project positions itself as compatible with ecosystems that rely on modern component frameworks, with React, Vue, Angular, Svelte, Lit, and testing-library style workflows among intended integrators.
Consumers install the package as a library dependency and configure their test environment to use Happy DOM as the global document and window implementation. Documentation covers getting started and setting up a test environment, plus contribution and licensing information.
Because it omits rendering and native browser chrome, Happy DOM trades visual fidelity for speed and simpler CI setups when tests only need DOM logic, event dispatch, or component mounting behavior.
Key features
- DOM APIs without real browser UI
- Custom elements and shadow DOM
- Mutation observer and tree walker
- Fetch API in the DOM context
- Test runner integration guides
- TypeScript and JavaScript support
- Web component oriented features
- MIT licensed npm package
Use cases
- Unit testing React or Vue components
- Running DOM code in Node or Bun
- Vitest or Jest environments without browser
- Web component logic verification