Test Patterns
This guide outlines the common test patterns and best practices used throughout Gradiant’s test suite.Test Organization
AAA Pattern
We follow the Arrange-Act-Assert pattern:Test Grouping
Group related tests using descriptivedescribe blocks:
Mocking Patterns
External Services
Use MSW for mocking HTTP requests:Database Operations
Use test containers and transactions:Async Testing
Promise Handling
Always use async/await for cleaner test code:WebSocket Testing
Test real-time communication:Error Handling
Expected Errors
Test both success and error cases:Test Data Management
Factories
Use factories for test data:Data Cleanup
Always clean up test data:Coverage Requirements
- Minimum 90% overall coverage
- 100% coverage for critical paths
- All error conditions must be tested
- All API endpoints must have integration tests
- All UI components must have snapshot tests