Testing Stack
Tests use:- Vitest - Fast unit test framework
- React Testing Library - Component testing utilities
- happy-dom - DOM environment (avoids ESM issues with jsdom)
Test Commands
Command Details
| Command | Description |
|---|---|
npm run test | Run tests in watch mode (re-runs on file changes). |
npm run test:run | Run the full test suite once. Use this before committing. |
npm run test:coverage | Run tests and generate a coverage report. Aims for at least 80% (thresholds in Vitest config). Open coverage/index.html in a browser to view the report. |
Configuration
Test configuration lives invite.config.ts:
Coverage Thresholds
All coverage metrics must meet 80% minimum:- Lines: 80%
- Functions: 80%
- Branches: 80%
- Statements: 80%
Coverage Scope
- Included
- Excluded
Testing Guidelines
When Adding Code
Write or extend tests for every new or changed behavior:- Unit tests for shared/server logic
- Component tests for UI
- The change is trivial (e.g. copy or config)
- That part of the codebase has no tests and the task is unrelated
When Removing Code
Remove or update the tests that covered the removed behavior so:- The suite stays accurate
- The test run stays green
Test Examples
Component Test Structure
Shared Logic Test Structure
Running Tests
Development Workflow
- During development: Run
npm run testto watch for changes - Before committing: Run
npm run test:runto ensure all tests pass - Coverage check: Run
npm run test:coverageto verify thresholds
Viewing Coverage Reports
After runningnpm run test:coverage:
- Open
coverage/index.htmlin a browser - Navigate through files to see:
- Line coverage
- Branch coverage
- Function coverage
- Uncovered lines highlighted
Best Practices
Test behavior, not implementation
Test behavior, not implementation
Focus on testing what the code does, not how it does it.
Use React Testing Library queries
Use React Testing Library queries
Prefer queries that mirror how users interact:
Keep tests isolated
Keep tests isolated
Each test should be independent:
Test edge cases
Test edge cases
Cover:
- Empty states
- Error conditions
- Boundary values
- Async operations
Continuous Integration
Tests run automatically in CI:- On every pull request
- Before merge to main
- Coverage reports uploaded to CI