Overview
The JOIP Web Application has a Jest-based testing infrastructure configured but not yet fully implemented. This guide covers the testing strategy, configuration, and how to add tests when the testing suite is enabled.Current Status: Jest configuration exists in
jest.config.js, but Jest and ts-jest packages are not installed. Tests are not currently run in CI/CD.Testing Infrastructure
Jest Configuration
The project includes a comprehensive Jest configuration for both backend and frontend testing:Test Directory Structure
Tests are organized into backend and frontend directories:Enabling Tests
Installation
To enable the testing suite, install the required dependencies:Testing Strategies
Backend Testing
Unit Tests for Database Operations
Test individual storage layer functions:Integration Tests for API Routes
Test complete API endpoints:Frontend Testing
Component Tests
Test React components in isolation:Page Tests
Test complete page components:Hook Tests
Test custom React hooks:Test Coverage Goals
Recommended Coverage Targets
- Backend Routes: 80%+ coverage
- Storage Layer: 90%+ coverage
- Shared Schemas: 100% coverage (validation logic)
- Frontend Components: 70%+ coverage
- Critical Features: 90%+ coverage (auth, sessions, payments)
Running Coverage Reports
Mocking Strategies
Mocking Database Operations
Mocking External APIs
Mocking Supabase Storage
Continuous Integration
GitHub Actions Workflow
Add testing to CI/CD pipeline:Best Practices
Test Organization
- Describe blocks: Group related tests with descriptive names
- It blocks: Write clear, specific test descriptions
- Arrange-Act-Assert: Structure tests with setup, action, and verification
- One assertion per test: Focus each test on a single behavior
- Test names: Use “should” statements that describe expected behavior
Test Data
- Factory functions: Create test data generators for consistent fixtures
- Cleanup: Always clean up test data in
afterEachorafterAll - Isolation: Each test should be independent and not rely on others
- Realistic data: Use data that resembles production scenarios
Mocking
- Mock external services: Don’t make real API calls in tests
- Mock sparingly: Only mock what’s necessary for the test
- Verify mocks: Assert that mocks were called with expected arguments
- Reset mocks: Clear mock state between tests