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.
| Vitest | Analog | Angular |
|---|---|---|
| Angular Versions | v17+ | v21+ |
| Support | Community | Angular 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
- Yarn
- pnpm
npm run test
yarn test
pnpm 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,describeetc fromvitestdirectly, you won't be able to runfakeAsync. Instead, use the functions (it,describeetc. the way you used to do in Jest/Jasmine – without any imports of these functions in the test file). -
vmThreadsis 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.mtsexport default defineConfig(({ mode }) => {
return {
test: {
pool: 'threads', // add this property
},
};
});