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

To migrate an existing Angular project from Karma and Jasmine to Vitest, first confirm that it uses Angular’s application build system, then install Vitest and a DOM emulator, switch the test target to Angular’s unit-test builder, and review test-specific build settings and custom runner behavior. Only after the runner is configured should you use Angular’s experimental Jasmine-to-Vitest schematic and manually inspect its changes. The migration is optional: Karma remains supported.

Is migrating an existing Angular project to Vitest supported?

Angular’s migration guide says that “Migrating an existing project to Vitest is considered experimental.” The Angular CLI uses Vitest as the default unit test runner for new projects, and the roadmap says Vitest became the primary runner after its stable release in Angular v21. However, the existing-project migration tool is still described as experimental. Angular continues to support Karma, so there is no general requirement to migrate. Angular’s migration guide, testing overview, and roadmap describe this status.

The documented migration path requires the Angular application build system. Check the project’s actual builder and workspace configuration before proceeding; a project using another or legacy build system cannot assume it is eligible for this path.

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

How do I migrate an existing Angular project from Karma and Jasmine to Vitest?

Treat the migration as two related but separate jobs: configure Angular CLI to run Vitest, then refactor and validate the tests. The schematic handles some source-code conversions, but it does not perform the CLI or build-configuration migration.

  1. Confirm the application build system

    Inspect the workspace’s build target and confirm that the project uses Angular’s application build system. The migration guide makes this a prerequisite. If it does not, resolve that build-system requirement before relying on the documented migration path. The guide cannot determine eligibility without examining your workspace.

  2. Install Vitest and a DOM emulator

    Angular’s example installs vitest and jsdom. The CLI detects happy-dom if it is installed; otherwise, it falls back to jsdom. Choose the emulator that suits the project, and check package versions against the Angular and Node.js compatibility requirements for your environment. The migration page does not enumerate compatible versions.

    npm install --save-dev vitest jsdom

    This is the guide’s example for installing Vitest with jsdom; it is not a version-pinned compatibility recipe.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Switch the Angular test builder

    In angular.json, change the project’s test target builder to @angular/build:unit-test. The builder defaults to tsconfig.spec.json and the ::development build target. Set these explicitly if your workspace needs different values. Refer to Angular’s migration guide for the configuration example.

  4. Review test-specific build options

    The Karma builder could accept options such as polyfills, assets, and styles directly under the test target; the unit-test builder does not. Compare those test settings with the development build configuration. If they differ, move the test-specific settings into a dedicated build target configuration. If they already match, Angular’s guide says no change is needed. This configuration review is independent of converting Jasmine test syntax. See the migration guide.

  5. Audit custom Karma behavior before removing its configuration

    Review karma.conf.js and any scripts or workspace projects that depend on it. Identify behavior that must be preserved:

    • Replace Karma reporters with Vitest-compatible alternatives.
    • Find equivalent plugins where a Karma plugin provided needed behavior.
    • For custom browser launchers, use the Vitest builder’s browsers option with an appropriate browser provider.
    • Coverage is available as an Angular CLI feature through ng test --coverage.

    For custom Vitest configuration, Angular documents using vitest.config.ts and connecting it through runnerConfig. Angular does not directly support the contents of custom configuration or third-party plugins, and may override test.projects and test.include. Check the migration guide before relying on custom settings.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  6. Choose Node DOM emulation or real-browser execution

    The default runs tests in Node with a DOM emulator, so it does not launch a browser. If tests need real-browser behavior, install a provider and configure browsers on the test target. Angular’s examples include Playwright for Chromium, Firefox, and WebKit; WebdriverIO for Chrome, Firefox, Safari, and Edge; and a preview provider for WebContainer environments. Confirm that a provider currently supports your required browser and project constraints before choosing it.

    The CLI enables headless mode when the CI environment variable is set or a browser name includes “Headless”; otherwise, it runs headed. See Angular’s migration guide and test command reference.

  7. Run the experimental Jasmine refactoring schematic

    After configuring the Vitest builder, run:

    ng g @schematics/angular:refactor-jasmine-vitest

    The schematic converts common patterns, including fit/fdescribe to .only, xit/xdescribe to .skip, spyOn to vi.spyOn, selected Jasmine matchers and spy factories to Vitest APIs, lifecycle hooks, and fail() to vi.fail(). It adds TODOs for patterns it cannot convert.

    Use options such as --project, --include, --file-suffix, --add-imports, --verbose, or --browser-mode when they fit the workspace and desired refactor. Consult Angular’s guide for option details.

    Free tools Windows power users keep installed

    One-click scans. No signup required.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  8. Manually review and finish the migration

    The schematic does not install dependencies, edit angular.json, migrate build options, delete karma.conf.js or test.ts, or fully handle complex or nested spy scenarios. Review every change, paying particular attention to spies and mocks, and resolve the TODOs. Then remove old setup files and Karma/Jasmine packages only after confirming no scripts or other projects still use them. Angular’s uninstall command is an example for a newly generated CLI project, not a complete package list for every workspace.

  9. Run the suite and fix remaining failures

    Run ng test and address failures manually; the schematic does not guarantee that all tests will pass. Interactive runs use watch mode by default, while CI behavior differs. Use Angular’s CLI reference for command behavior and the migration guide for migration-specific direction.

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

What should I do about Zone.js test utilities?

If existing tests depend on fakeAsync, flush, or waitForAsync, Angular documents adding zone.js/plugins/vitest-patch to the test target’s polyfills. Treat this as a compatibility bridge, not as a guarantee that all Zone.js behavior is identical under Vitest. Angular recommends planning a move toward native async patterns and Vitest fake timers. See the migration guide.

Which migration approach fits the project?

  • Build-system readiness: the documented migration requires Angular’s application build system. If the workspace does not use it, this path is not ready to apply as written.
  • Browser requirements: a DOM emulator runs in Node without launching a browser; tests that require real browser execution need a provider and browser configuration.
  • Custom Karma behavior: numerous custom reporters, plugins, or launchers mean more manual mapping and validation before old configuration can be removed.
  • Zone.js reliance: tests using Zone.js utilities can use Angular’s documented patch, but teams should plan for native async and Vitest timers.
  • Refactor effort: common Jasmine patterns can be converted by the experimental schematic, while complex spies, mocks, and unrecognized patterns need manual attention.

Angular’s cited guidance provides no migration success rate or benchmark figures, so it does not establish a speed improvement for a particular project.

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.