Test Framework
The core package uses:- Vitest: Fast unit test runner (compatible with Jest API)
- @testing-library/react: React component testing utilities
- happy-dom: Lightweight DOM implementation for tests
Running Tests
Run All Tests
From the repository root:Run Core Package Tests
To run tests specifically in the core package:Watch Mode
Run tests in watch mode during development:Run Specific Test Files
Test Configuration
The test setup is defined inpackages/core/vitest.config.ts:
- environment: “happy-dom”: Provides a lightweight DOM for component testing
- tsconfigPaths: Resolves TypeScript path aliases from
tsconfig.json
Writing Tests
Component Tests
Use React Testing Library to test components:Hook Tests
Test custom hooks with@testing-library/react:
Testing with Context
Wrap components with required providers:Test Organization
File Naming
Place test files next to the code they test:Test Structure
Organize tests usingdescribe blocks:
Code Quality
Type Checking
Run TypeScript type checking:Linting
Lint the core package:Test Coverage
Generate coverage reports:Continuous Integration
Tests run automatically on:- Pull requests to
main - Before publishing packages
- As part of the release process
Best Practices
Test user behavior, not implementation
Focus on testing what users see and interact with, not internal component state or implementation details.
Use meaningful test descriptions
Write clear
describe and it statements that explain what is being tested.Mock external dependencies
Use Vitest’s mocking capabilities to isolate components from external APIs or services.
Debugging Tests
Run in UI Mode
Vitest provides an interactive UI for debugging:Use Console Logs
Debug component output:VS Code Debugging
Add a.vscode/launch.json configuration: