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.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe 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
jasmineAPIs (spies,fakeAsyncuse) and keep CI green at each step. - Tests that query library-internal classes such as
.mat-mdc-select-triggerbreak between versions. - A harness is a test API the component authors maintain: for example
MatSelectHarnesswithopen(),getOptions()andclickOptions({ 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
- Why move from Karma to Vitest?
- How would you migrate 1,800 tests safely?
- 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 voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.