Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/docs-app/docs/features/testing/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ pnpm run test

You can also [add Vitest](/docs/features/testing/vitest) to your existing project.

## IDE Support

Tests can also be run directly from your IDE using the Vitest [IDE integrations](https://vitest.dev/guide/ide) 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).
Expand Down
24 changes: 4 additions & 20 deletions apps/docs-app/docs/features/testing/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Next, define a `src/test-setup.ts` file to setup the `TestBed`:
If you are using `Zone.js` for change detection, import the `setup-zone` script. This script automatically includes support for setting up snapshot tests.

```ts
import '@angular/compiler';
import '@analogjs/vitest-angular/setup-zone';

import {
Expand All @@ -126,6 +127,7 @@ getTestBed().initTestEnvironment(
If you are using `Zoneless` change detection, use the following setup:

```ts
import '@angular/compiler';
import '@analogjs/vitest-angular/setup-snapshots';

import { provideZonelessChangeDetection, NgModule } from '@angular/core';
Expand Down Expand Up @@ -171,14 +173,14 @@ Next, update the `test` target in the `angular.json` to use the `@analogjs/vites

> You can also add a new target and name it `vitest` to run alongside your `test` target.

Lastly, add the `src/test-setup.ts` to `files` array in the `tsconfig.spec.json` in the root of your project, set the `target` to `es2016`, and update the `types`.
Lastly, add the `src/test-setup.ts` to `files` array in the `tsconfig.spec.json` in the root of your project, set the `target` to `es2022`, and update the `types`.

```json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"target": "es2016",
"target": "es2022",
"types": ["vitest/globals", "node"]
},
"files": ["src/test-setup.ts"],
Expand Down Expand Up @@ -255,24 +257,6 @@ export default defineConfig(({ mode }) => ({
}));
```

Next, add the `@angular/compiler` import to the `src/test-setup.ts` file.

```ts
import '@angular/compiler';
import '@analogjs/vitest-angular/setup-zone';

import {
BrowserTestingModule,
platformBrowserTesting,
} from '@angular/platform-browser/testing';
import { getTestBed } from '@angular/core/testing';

getTestBed().initTestEnvironment(
BrowserTestingModule,
platformBrowserTesting(),
);
```

## Running Tests

To run unit tests, use the `test` command:
Expand Down
Loading