Posted 12/21/2024
This post summarizes commonly used commands for running Angular unit tests with Karma during local development and CI.
npm t -- --include src\app\shared\user\user.service.spec.ts
For projects generated by angular CLI.
ng test
This starts Karma in watch mode by default.
Explicit watch mode (useful when scripting):
ng test --watch
Recommended for CI pipelines:
ng test --watch=false --browsers=ChromeHeadless
ng test --code-coverage
The report is generated in: coverage/
Open coverage/index.html to inspect detailed metrics.