Ana içeriğe atla

Running Tests

Analog supports Vitest for running unit tests.

Vitest Features

Vitest supports many features:

  • A Jest-compatible API.
  • Supports Vite's config, transforms, resolvers, and plugins.
  • Smart & instant watch mode.
  • TypeScript support.
  • Jest-compatible snapshots.
  • jsdom for DOM mocking.
  • In-source testing.
  • And more ...

You can also add Vitest to your existing project.

Angular support for Vitest

In Angular v21, stable support for Vitest directly through the Angular CLI was introduced for new Angular projects. While both Analog and Angular support running tests with Vitest, there are some similarities and key differences.

The table below shows the features available across both choices.

VitestAnalogAngular
Angular Versionsv17+v21+
SupportCommunityAngular Team
Builders
Schematics
Migrations
Fully Configurable⚠️
Vitest CLI
Vitest Workpsaces
Custom Environments
Custom Providers
IDE extensions
Buildable Libs
Module Mocking/Graph
Plugins/Types

The table above is not to compare the two solutions, but to provide the information on what features are supported by each implementation. Choose the solution that best fits your needs and priorities.

Running Unit Tests

To run unit tests, use the test command:

npm run test

IDE Support

Tests can also be run directly from your IDE using the Vitest IDE integrations for VS Code or JetBrains IDEs.

Known limitations

  • Only globals are patched with Zone.js. This means, that if you import it, describe etc from vitest directly, you won't be able to run fakeAsync. Instead, use the functions (it, describe etc. the way you used to do in Jest/Jasmine – without any imports of these functions in the test file).

  • vmThreads is used. This can lead to potential memory leaks and is used as a default to provide an environment closer to the Jest with JSDOM. More details you can read here.

    To change that – adjust your vite.config.mts

    export default defineConfig(({ mode }) => {
    return {
    test: {
    pool: 'threads', // add this property
    },
    };
    });