Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Karma and Jasmine remain supported for Angular projects, but new Angular CLI projects currently use Vitest by default. Choose Karma when you are maintaining an existing Karma suite, need its browser-based workflow, or have a specific compatibility reason—not because it is the default for new projects.

When to use Karma and Jasmine in Angular

Karma launches tests in a browser; Jasmine provides the test framework and familiar functions such as describe and it. Angular’s current testing guide documents setup for both new and existing projects and describes Karma as supported. By contrast, Angular’s testing overview identifies Vitest as the default for new CLI projects. The overview describes Vitest’s default Node.js and jsdom setup as avoiding the need to launch a browser; Karma’s workflow launches one.

For a new project, select Karma explicitly if it fits your needs. For an existing project, weigh browser execution, compatibility with current tests and configuration, CI setup, and the work involved in changing runners. Angular’s migration guide characterizes migration from Karma/Jasmine to Vitest as experimental and says it requires the application build system; it does not establish that every Karma project should migrate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create or configure a Karma project

Scaffold a new project

Angular documents this command to create a project configured for Karma and Jasmine:

ng new my-karma-app --test-runner=karma

Add Karma to an existing project

Install the development dependencies listed in Angular’s guide using your package manager:

  • karma
  • karma-chrome-launcher
  • karma-coverage
  • karma-jasmine
  • karma-jasmine-html-reporter
  • jasmine-core
  • @types/jasmine

Then configure the Angular workspace test target in angular.json to use the Karma runner. In tsconfig.spec.json, include jasmine in the types array so TypeScript recognizes Jasmine globals such as describe and it. The Angular CLI assembles Karma’s configuration from workspace options. If you need custom Karma settings, generate a configuration file with:

ng generate config karma

Run tests locally and in CI

Watch tests during development

Run ng test to build in watch mode and launch Karma. In the documented Karma workflow, results appear in the browser through the Jasmine HTML reporter, and a source change triggers another run.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run a single headless pass in CI

Angular’s Karma guide gives this example command for a non-interactive run:

ng test --no-watch --no-progress --browsers=ChromeHeadless

--no-watch makes the run single-pass rather than waiting for file changes, and --no-progress suppresses progress output. ChromeHeadless requests Chrome without a visible window. Make sure the browser and runner configuration are available in the CI environment; the command alone does not install or configure them.

Debug a failing browser test

  1. Make the Karma browser visible, then select DEBUG to open a test tab.
  2. Open the test file in the browser’s developer tools and set a breakpoint.
  3. Refresh the test tab to run the tests again and stop at the breakpoint.

Configure coverage thresholds

Angular’s Karma guide shows coverage output configured in karma.conf.js and a check threshold for statements, branches, functions, and lines. Its example sets each threshold to 80 percent. Treat those figures as example configuration values, not a required target or a universal coverage standard. Set thresholds that reflect the project’s policy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use Angular testing utilities with Jasmine

Jasmine describes individual tests, but Angular components often also need Angular’s testing environment. TestBed configures that environment, while ComponentFixture gives a test access to a component instance and its rendered view. These Angular concepts are useful regardless of the particular Jasmine syntax in a test. Angular’s testing utility API documentation notes that it is being updated for Vitest and that some explanations and examples remain in a Karma/Jasmine context.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.