This document provides information about the testing setup for the Debt Cycles Dashboard.
The application includes several types of tests:
- Unit tests for individual components and functions
- Integration tests for services like the FRED API and database
- Mock implementations for external dependencies
npm testnpm run test:watchnpm run test:coverage./scripts/test-database.shTests are organized in the following directories:
app/__tests__/components/- Component testsapp/__tests__/hooks/- React hook testsapp/__tests__/services/- API service testsapp/__tests__/database/- Database service testsapp/__tests__/integration/- Integration testsapp/__tests__/mocks/- Mock implementations and helpers
The test suite uses several mock implementations:
The Prisma client is mocked in jest.setup.js to avoid actual database connections during tests. It provides mock implementations for all the database operations used in the application.
API calls to the FRED service are mocked using:
- Mock Service Worker (MSW) for HTTP request interception
- Mock responses in
app/__tests__/mocks/fredApiResponses.ts
UI components are tested using:
- React Testing Library for component rendering and interactions
- Jest DOM matchers for assertions
The database tests verify that:
- Data can be cached correctly
- The system properly determines when to refresh data
- Cached data is returned when available
- API calls are made only when necessary
When writing new tests:
- Place tests in the appropriate directory based on what you're testing
- Follow the naming convention:
*.test.tsor*.test.tsx - Use existing mocks or create new ones as needed
- Keep tests focused on a single responsibility
If tests are failing:
- Check that environment variables are properly mocked
- Verify mock implementations match the current code structure
- Look for timing issues with asynchronous operations
- Ensure the test environment is properly set up in
jest.setup.js