happy-dom
Run DOM tests without a browser using Happy DOM — fast JavaScript DOM implementation. Use when someone asks to "test without a browser", "Happy DOM", "fast DOM environment for tests", "replace jsdom", "Vitest DOM environment", or "server-side DOM". Covers test environment setup, Vitest/Jest integration, SSR testing, and performance comparison with jsdom.
What this skill does
# Happy DOM
## Overview
Happy DOM is a JavaScript DOM implementation for Node.js — 3-10x faster than jsdom. It provides `window`, `document`, `HTMLElement`, and 1000+ Web APIs without launching a browser. Use it as the test environment for Vitest or Jest when testing UI components, or for server-side DOM manipulation (email templates, HTML generation, scraping).
## When to Use
- Test environment for React/Vue/Svelte component tests (faster than jsdom)
- Vitest setup — Happy DOM is the recommended environment
- Server-side HTML generation or manipulation
- Parsing and extracting data from HTML strings
- Email template rendering on the server
## Instructions
### Vitest Integration
```bash
npm install -D happy-dom
```
```typescript
// vitest.config.ts — Use Happy DOM for all tests
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
environment: "happy-dom",
},
});
```
That's it — all tests now run with Happy DOM providing DOM APIs.
### Per-File Environment
```typescript
// tests/component.test.ts — Override environment for specific tests
// @vitest-environment happy-dom
import { render, screen } from "@testing-library/react";
test("renders heading", () => {
render(<h1>Hello</h1>);
expect(screen.getByRole("heading")).toHaveTextContent("Hello");
});
```
### Jest Integration
```javascript
// jest.config.js
module.exports = {
testEnvironment: "@happy-dom/jest-environment",
};
```
### Standalone Usage
```typescript
// render.ts — Server-side DOM manipulation
import { Window } from "happy-dom";
const window = new Window({ url: "https://localhost:3000" });
const document = window.document;
// Parse HTML
document.body.innerHTML = `
<div class="container">
<h1>Hello World</h1>
<ul id="items">
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
`;
// Query and manipulate
const heading = document.querySelector("h1");
console.log(heading?.textContent); // "Hello World"
const items = document.querySelectorAll("#items li");
console.log(items.length); // 2
// Create elements
const newItem = document.createElement("li");
newItem.textContent = "Item 3";
document.getElementById("items")?.appendChild(newItem);
// Serialize back to HTML
console.log(document.body.innerHTML);
// Clean up
await window.happyDOM.close();
```
### Email Template Rendering
```typescript
// email.ts — Render email templates server-side
import { Window } from "happy-dom";
function renderEmailTemplate(template: string, data: Record<string, string>): string {
const window = new Window();
const document = window.document;
document.body.innerHTML = template;
// Replace placeholders
for (const [key, value] of Object.entries(data)) {
const elements = document.querySelectorAll(`[data-field="${key}"]`);
elements.forEach((el) => { el.textContent = value; });
}
const html = document.body.innerHTML;
window.happyDOM.close();
return html;
}
```
## Examples
### Example 1: Speed up Vitest test suite
**User prompt:** "Our Vitest tests using jsdom take 45 seconds. Make them faster."
The agent will switch the test environment to Happy DOM (one config change), verify all tests still pass, and benchmark the improvement (typically 3-5x faster).
### Example 2: Parse and extract data from HTML
**User prompt:** "Parse HTML pages and extract structured data without a browser."
The agent will use Happy DOM to parse HTML strings, query elements with CSS selectors, and return structured data.
## Guidelines
- **One config line for Vitest** — `environment: "happy-dom"` in vitest.config.ts
- **3-10x faster than jsdom** — measurable improvement on large test suites
- **1000+ Web APIs** — `fetch`, `FormData`, `URL`, `MutationObserver`, `IntersectionObserver`
- **Not 100% browser-identical** — some edge cases differ; test critical paths in a real browser
- **`window.happyDOM.close()`** — clean up resources in standalone usage
- **Works with Testing Library** — `@testing-library/react` works unchanged
- **Lighter than jsdom** — less memory, faster startup
- **SSR testing** — render components server-side and assert on HTML output
- **Per-file override** — `// @vitest-environment happy-dom` for specific tests
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.