Test Framework
Air Tracker uses the following testing tools:- Jasmine (~5.9.0) - Testing framework with BDD-style syntax
- Karma (~6.4.0) - Test runner that executes tests in real browsers
- @angular/build:karma - Angular’s Karma builder integration
- karma-chrome-launcher - Runs tests in Chrome/Chromium
- karma-coverage - Generates code coverage reports
Running Tests
Run All Tests
Run the complete test suite:- Start the Karma test runner
- Launch Chrome browser
- Execute all
*.spec.tsfiles - Watch for file changes and re-run tests
Single Run (CI Mode)
Run tests once without watching:Headless Mode
Run tests in headless Chrome (useful for CI/CD):Run Specific Tests
Run tests matching a pattern:Test Configuration
Tests are configured inangular.json:
Writing Tests
Component Tests
Air Tracker uses standalone components, so tests import the component directly. Example fromflights-shell.component.spec.ts:
Service Tests
Example service test structure:Testing Components with Signals
Air Tracker uses Angular signals extensively. Example:Testing HTTP Services
Example testing HTTP calls:Testing Async Operations
UsefakeAsync and tick for timing control:
Test Patterns from Codebase
Basic Component Test
Location:src/app/features/flights/flights-shell/flights-shell.component.spec.ts
Service with Dependencies
Test services with mocked dependencies:Code Coverage
Generate Coverage Report
coverage/ directory.
View Coverage Report
Opencoverage/index.html in your browser:
Coverage Goals
Aim for:- Statements: 80%+
- Branches: 75%+
- Functions: 80%+
- Lines: 80%+
Testing Best Practices
1. Test Behavior, Not Implementation
2. Use Descriptive Test Names
3. Arrange-Act-Assert Pattern
4. Mock External Dependencies
Always mock HTTP calls, timers, and external services:5. Clean Up After Tests
Debugging Tests
Run Tests in Debug Mode
- Run tests:
ng test - Click “Debug” button in Karma browser window
- Open DevTools (F12)
- Set breakpoints in test code
- Refresh to re-run tests
Focus on Specific Tests
Common Testing Issues
Issue: “No provider for HttpClient”
Solution: ImportHttpClientTestingModule
Issue: “Can’t bind to ‘input’ since it isn’t a known property”
Solution: Import the component/module that declares the directiveIssue: Async test timeout
Solution: Increase timeout or usefakeAsync
Next Steps
- Review code style guidelines
- Learn about component development
- Read the contributing guide
