This project uses Jest as the testing framework with React Testing Library for component testing.
npm test- Run all testsnpm run test:watch- Run tests in watch mode (automatically re-runs when files change)npm run test:coverage- Run tests with coverage reportnpm run test:ci- Run tests in CI mode (no watch, with coverage)
Tests are organized using the following pattern:
src/
components/
ComponentName/
__tests__/
Component.test.js
utils/
__tests__/
utilFunction.test.js
Use React Testing Library for component testing:
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import MyComponent from '../MyComponent';
describe('MyComponent', () => {
test('renders correctly', () => {
render(<MyComponent />);
expect(screen.getByText('Expected Text')).toBeInTheDocument();
});
});For pure functions and utilities:
import { myUtilFunction } from '../myUtil';
describe('myUtilFunction', () => {
test('returns expected result', () => {
expect(myUtilFunction('input')).toBe('expected output');
});
});Highcharts is automatically mocked in the test setup (src/setupTests.js).
Mock fetch utilities in individual tests:
jest.mock('../../../utils/fetchUtil', () => ({
fetchJson: jest.fn(),
}));Coverage thresholds are set to 70% for:
- Statements
- Branches
- Functions
- Lines
The coverage report is generated in the coverage/ directory when running npm run test:coverage.
Common browser APIs are mocked in src/setupTests.js:
- IntersectionObserver
- ResizeObserver
- window.matchMedia
Test files are configured to recognize Mocha and Jest globals.