Running Unit Tests with Angular CLI
Show how to use Angular CLI to execute unit tests using Karma and Jasmine, including watching for file changes.
Run this command in the terminal within your Angular project to execute all unit tests using Karma and Jasmine. The Angular CLI will compile the application and launch the Karma test runner. The tests will be carried out in a browser instance automatically.
ng test --watch=true
Adding the `--watch=true` flag to the `ng test` command will keep the test runner active after running the tests, monitoring for any file changes. If any test-related files are modified, the tests will rerun automatically, facilitating test-driven development.
ng test --code-coverage
Including the `--code-coverage` flag tells the Angular CLI to calculate code coverage statistics. After test execution, it will generate a coverage report showing how much of your code is covered by unit tests.