Test Stack
- Test Runner: Vitest (fast, Vite-powered)
- Testing Library: @testing-library/react
- Assertions: Vitest + @testing-library/jest-dom
- Environment: jsdom (browser simulation)
- Mocking: Vitest mocking utilities
Setup
Configuration
The test configuration is defined invitest.config.ts:
Setup File
The setup file atsrc/test/setup.ts imports testing utilities:
Mock Utilities
Common mocks are available insrc/test/mocks/supabase.ts for Supabase client testing.
Running Tests
Test Commands
Defined inpackage.json:
Pre-commit Testing
ALWAYS run tests before committing:Testing Patterns
Component Testing
Example fromsrc/features/landing/__tests__/landing-components.test.tsx:
Context Testing
Example fromsrc/features/auth/context/__tests__/AuthContext.test.tsx:
Service Testing
Example fromsrc/features/subscription/services/__tests__/subscription-service.test.ts:
Store Testing (Zustand)
Example fromsrc/features/wizard/__tests__/wizard-store.test.ts:
User Interaction Testing
Using@testing-library/user-event:
Test Organization
File Naming
Test files use the.test.ts or .test.tsx suffix:
Test Structure
Use descriptivedescribe and it blocks:
Mocking
Supabase Mocking
Use the provided mock utilities:Module Mocking
Function Mocking
Testing Checklist
Before committing:- All existing tests pass
- New features have tests
- Edge cases are covered
- Async operations use
waitFor - Mocks are properly cleaned up
- Tests are isolated and independent
-
npm run build && npm testsucceeds
Best Practices
- Test behavior, not implementation: Focus on what the user sees and does
- Use Testing Library queries: Prefer
getByRole,getByLabelTextovergetByTestId - Avoid testing internals: Don’t test private functions or state directly
- Keep tests focused: One assertion per test when possible
- Clean up: Use
beforeEach/afterEachto reset state - Async handling: Always use
waitForfor async operations - Mock external dependencies: Supabase, API calls, etc.
Coverage Goals
Aim for good test coverage on:- Core business logic (subscription, payment flows)
- Authentication and authorization
- State management (Zustand stores)
- Critical user paths (wizard, checkout)
- API integrations
Debugging Tests
Common Issues
Timeout Errors
Increase timeout for slow tests:Act Warnings
Wrap state updates inact():