Testing Philosophy
We follow a comprehensive testing strategy that balances coverage with development speed:- Unit Tests - Test individual functions and components in isolation
- Integration Tests - Test how components work together
- End-to-End Tests - Test complete user flows in a real browser
Testing Stack
Our testing infrastructure uses modern, industry-standard tools:- Vitest - Fast unit test runner
- React Testing Library - Component testing utilities
- Playwright - End-to-end testing framework
- MSW (Mock Service Worker) - API mocking
Unit Testing
Setup
Vitest configuration invitest.config.ts:
Test Setup File
Configure test environment insrc/test/setup.ts:
Testing Components
1
Basic Component Test
Test component rendering and basic interactions:
2
Testing with Props
Test different prop combinations:
3
Testing Hooks
Test custom React hooks:
Testing Utilities
Create reusable test utilities insrc/test/utils.tsx:
Integration Testing
API Mocking with MSW
Set up Mock Service Worker for API mocking:Testing API Integration
End-to-End Testing
Playwright Setup
Configure Playwright inplaywright.config.ts:
Writing E2E Tests
Advanced E2E Patterns
Authentication State
Authentication State
Reuse authentication state across tests:
API Mocking in E2E
API Mocking in E2E
Mock API responses in E2E tests:
Running Tests
Test Coverage
Maintain high test coverage for critical code:- Statements: > 80%
- Branches: > 75%
- Functions: > 80%
- Lines: > 80%
Best Practices
Do’s
- Write tests alongside your code
- Test user behavior, not implementation details
- Use descriptive test names
- Keep tests isolated and independent
- Mock external dependencies
- Test error states and edge cases
Don’ts
- Don’t test third-party libraries
- Don’t test implementation details (CSS classes, state)
- Don’t write flaky tests
- Don’t skip tests without good reason
- Don’t have test dependencies on each other