Skip to main content

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:
1

Install Testing Dependencies

2

Add Test Script

Add the test script to package.json:
package.json
3

Create Test Setup File

Create tests/setup.ts:
tests/setup.ts
4

Run Tests

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

  • 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

Output:

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

  1. Describe blocks: Group related tests with descriptive names
  2. It blocks: Write clear, specific test descriptions
  3. Arrange-Act-Assert: Structure tests with setup, action, and verification
  4. One assertion per test: Focus each test on a single behavior
  5. Test names: Use “should” statements that describe expected behavior

Test Data

  1. Factory functions: Create test data generators for consistent fixtures
  2. Cleanup: Always clean up test data in afterEach or afterAll
  3. Isolation: Each test should be independent and not rely on others
  4. Realistic data: Use data that resembles production scenarios

Mocking

  1. Mock external services: Don’t make real API calls in tests
  2. Mock sparingly: Only mock what’s necessary for the test
  3. Verify mocks: Assert that mocks were called with expected arguments
  4. Reset mocks: Clear mock state between tests

Next Steps