Testing Guide
The T1 Component Library uses Jest and React Testing Library for comprehensive component testing. This guide covers the testing setup, patterns, and best practices.Testing Setup
Jest Configuration
The test configuration is defined injest.config.js:1:
Coverage Requirements
The project enforces 80% coverage threshold across all metrics (jest.config.js:33):
Test Setup File
Thejest.setup.ts:1 file configures the testing environment:
Running Tests
The package.json defines three test commands (package.json:10):
Run all tests
Run tests in watch mode
Run tests with coverage report
Test Structure
Organizing Tests
Tests are organized in__tests__/ directories with descriptive describe blocks:
Testing Patterns
Testing Rendering
FromButton.test.tsx:7:
Testing Variants
FromButton.test.tsx:23:
Testing Sizes
FromButton.test.tsx:61:
Testing Interactions
FromButton.test.tsx:81:
Testing Loading States
FromButton.test.tsx:110:
Testing Icons
FromButton.test.tsx:138:
Testing Ref Forwarding
FromButton.test.tsx:187:
Testing Custom Classes
FromButton.test.tsx:180:
Testing Composite Components
FromCard.test.tsx:249:
Best Practices
1. Use Semantic Queries
Prefer role-based queries over test IDs:2. Test User Behavior
Focus on how users interact with components:3. Test Accessibility
4. Test Edge Cases
5. Organize Tests Logically
Group related tests in describe blocks:Coverage Reports
View coverage reports after running:coverage/ directory:
coverage/lcov-report/index.html- Visual HTML reportcoverage/coverage-final.json- JSON report