Overview
Unit tests run your component and hook logic in isolation using Vitest with happy-dom. They’re fast, don’t require the inspector or a browser, and are included in the defaultsunpeak test run.
Setup
Unit tests live intests/unit/ (or any *.test.ts / *.spec.ts file matched by your Vitest config). For sunpeak framework projects, Vitest is pre-configured with happy-dom.
For standalone usage, add Vitest to your project:
Writing Unit Tests
Test component rendering, hook logic, and data transformations without the full inspector stack.Testing Components
Testing Data Transformations
Testing Tool Handlers
Tool handlers are plain async functions, so you can test them directly:When to Use Unit Tests vs E2E Tests
| Use unit tests for | Use E2E tests for |
|---|---|
| Data transformations and utilities | Visual rendering across hosts and themes |
| Tool handler logic | Iframe communication and sandbox behavior |
| Component logic in isolation | Full tool call flow (call → render → assert) |
| Fast feedback during development | Cross-host compatibility (ChatGPT vs Claude) |
Additional Quality Tools
Linting (ESLint)
Linting (ESLint)
"lint": "eslint . --ext .ts,.tsx" to package.json scripts.Type Checking
Type Checking
TypeScript is already installed. Add to package.json scripts:
Formatting (Prettier)
Formatting (Prettier)
"format": "prettier --write ." to package.json scripts.Learn More
Vitest Docs
Learn more about Vitest for unit testing.
E2E Testing
Full-stack testing with the inspector and Playwright.