Skip to the page

Production and testing · mid

Vitest, Karma migration and component harnesses

Vitest is the default test runner since v21. Component harnesses give stable test APIs instead of library CSS classes.

The notes

What you must know

  • Karma is deprecated and gets no new features (bank answer). Vitest is the default since v21 (facts.md), through @angular/build:unit-test.
  • Vitest starts faster, has a good watch mode and native ESM.
  • The experimental Jest and Web Test Runner builders were scheduled for removal in v22.
  • Migration of 1,800 Karma tests: use the official migrations, move in groups, fix jasmine APIs (spies, fakeAsync use) and keep CI green at each step.
  • Tests that query library-internal classes such as .mat-mdc-select-trigger break between versions.
  • A harness is a test API the component authors maintain: for example MatSelectHarness with open(), getOptions() and clickOptions({ text: "Pune" }).
  • Harnesses wait for async work and change detection for you.

The red pen

Common traps: mistake → fix

  • Mistake: Switching runner needs a rewrite of all tests

    Fix: migrations handle much; spy syntax needs review.

  • Mistake: CSS class queries on library components are stable

    Fix: they change between versions.

Easy to hard

Questions interviewers ask, easy to hard

  1. Why move from Karma to Vitest?
  2. How would you migrate 1,800 tests safely?
  3. Why use component harnesses?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview