Testing Framework
Paginator uses the following testing stack:- Karma (v6.4.0): Test runner
- Jasmine (v5.5.0): Testing framework
- Angular Testing Utilities: Component testing tools
Running Tests
Basic Test Execution
Run all unit tests in watch mode:- Launches Karma test runner
- Opens Chrome browser
- Watches for file changes
- Re-runs tests automatically
Running Tests with Coverage
Generate a code coverage report:- Run all tests once (no watch mode)
- Generate coverage reports in
coverage/directory - Display coverage summary in the terminal
Coverage Report Location
After running tests with coverage, reports are available at:Test Configuration
Karma Configuration
Test configuration is defined inangular.json under the test architect:
TypeScript Configuration
Test-specific TypeScript settings are intsconfig.spec.json.
Test File Structure
All test files follow the.spec.ts naming convention and are located alongside their source files:
Existing Test Files
Core Module Tests:src/app/core/components/loading/loading.component.spec.tssrc/app/core/services/loading.service.spec.tssrc/app/core/services/theme.service.spec.tssrc/app/core/interceptors/loading.interceptor.spec.ts
src/app/features/paginator/components/filters/filters.component.spec.tssrc/app/features/paginator/components/header/header.component.spec.tssrc/app/features/paginator/components/pagination/pagination.component.spec.tssrc/app/features/paginator/components/table/table.component.spec.tssrc/app/features/paginator/page/home/home.component.spec.tssrc/app/features/paginator/services/locations.service.spec.ts
src/app/app.component.spec.ts
Writing Tests
Component Test Example
Basic structure of a component test:Service Test Example
Basic structure of a service test:Test Polyfills
The following polyfills are automatically included for testing:zone.js: Angular’s zone-based change detectionzone.js/testing: Testing utilities for zones
Best Practices
- Test Coverage: Aim for at least 80% code coverage
- Isolation: Test components and services in isolation
- Descriptive Names: Use clear
describeanditblock names - Setup/Teardown: Use
beforeEachandafterEachappropriately - Mock Dependencies: Mock external dependencies and services
- Test User Interactions: Test component interactions and events
- Async Testing: Use
asyncandfakeAsyncfor asynchronous operations
Continuous Testing
For development, keep tests running in watch mode:Debugging Tests
When Karma launches Chrome, click the “Debug” button to:- Open Chrome DevTools
- Set breakpoints in your test code
- Step through test execution
- Inspect variables and state