How to Progressively Migrate to Vitest Browser Mode
In this recipe, you will find a step-by-step guide to progressively migrate your Angular tests to Vitest Browser Mode.
Vitest & Browser Mode are officially supported by Angular CLI starting from Angular v21.0.0 (Nov. 2025).
For older Angular versions or more advanced scenarios, you can use Angular Vite plugin by Analog.
Note that Nx added Angular Vitest support in Nx v20.1.0 (Nov. 28th 2024).
๐ฝ๏ธ Before You Startโ
๐๏ธ Browser Mode
The evolution of Angular browser testing and how to configure Vitest Browser Mode for both partial and full Playwright-powered testing.
1. Migrate to "Partial" Browser Modeโ
When using Vitest with the Angular CLI, the default behavior is to use an emulated environment. Either JSDOM or Happy DOM depending on the first dependency that is available.
To enable browser mode in Angular CLI, you have to update the browsers option to use the browser you want to use:
{
"test": {
"builder": "@angular/build:unit-test",
"options": {
"runner": "vitest",
"browsers": ["Chromium"]
}
}
}
You will then also have to add the required dependencies to your project.
npm install -D playwright vitest @vitest/browser-playwright
After enabling this, the tests will run in the browser. Angular CLI will automatically either use Playwright or WebdriverIO as the Vitest browser provider depending on which package is installed in your workspace.
At this stage, the tests are running in the browser but you are not leveraging the full power of the browser provider yet.
Cf. "Partial" Browser Mode.