본문으로 건너뛰기

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 ...

Running Unit Tests

To run unit tests, use the test command:

npm run test

You can also add Vitest to your existing project.

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
    },
    };
    });