Skip to content
Back to skills

Angular Testing

ASecurity

For Angular v20 and later, use the Angular CLI unit-test builder with Vitest. New CLI projects are already configured this way. The CLI owns the Angular/Vitest integration, so a normal project does not need a second Vite plugin configuration or a second `TestBed` initialization. In `angular.json`, the project test target should use `@angular/build:unit-test`: ```json { "projects": { "my-app": { "architect": { "test": { "builder": "@angular/build:unit-test", "options": { "tsConfig": "tsconfig....

  • 584 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 5, 2026
developmentbashangulartestingapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 18 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill angular-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Angular Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Angular Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-angular-testing-d342b5bc/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-angular-testing-d342b5bc)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Setting up Vitest for Angular testing

For Angular v20 and later, use the Angular CLI unit-test builder with Vitest. New CLI projects are already configured this way. The CLI owns the Angular/Vitest integration, so a normal project does not need a second Vite plugin configuration or a second `TestBed` initialization.

In `angular.json`, the project test target should use `@angular/build:unit-test`:

```json
{
  "projects": {
    "my-app": {
      "architect": {
        "test": {
          "builder": "@angular/build:unit-test",
          "options": {
            "tsConfig": "tsconfig.spec.json",
            "buildTarget": "my-app:build"
          }
        }
      }
    }
  }
}
```

`tsConfig` and `buildTarget` can use the project's existing names; the builder supplies defaults when they are omitted. If migrating from Karma, review and move any test-specific assets, styles, or polyfills into the appropriate build configuration because the unit-test builder does not accept all of the old Karma builder options. Remove the old Karma configuration and packages only after checking for project-specific behavior.

Run the tests through the Angular CLI:

```bash
ng test                         # watch mode locally
ng test --no-watch --no-progress # single-run CI-style execution
ng test --coverage              # coverage report
```

The usual `TestBed`, `ComponentFixture`, harness, and Angular testing APIs remain the same. In a Vitest spec, use Vitest assertions and spies consistently—for example, import `vi` from `vitest` when globals are disabled—rather than mixing Jasmine spies and matchers into a Vitest suite.

For global test setup, use the builder's `setupFiles` option. For example:

```json
{
  "test": {
    "builder": "@angular/build:unit-test",
    "options": {
      "setupFiles": ["src/test-setup.ts"]
    }
  }
}
```

Use a custom `runnerConfig` only for advanced Vitest settings; the Angular CLI still controls the Angular test project and included spec files. If existing tests depend on `fakeAsync`, `flush`, or `waitForAsync`, add `zone.js/plugins/vitest-patch` to the test target's polyfills as a migration aid. Prefer native `async`/`await` and Vitest fake timers for new tests where possible.

If the project is intentionally managed by a standalone Vite pipeline rather than Angular CLI, install compatible versions of `vitest`, `jsdom`, and the chosen Angular Vite integration, configure the `jsdom` environment and spec include pattern there, and initialize Angular's test environment exactly once. Do not combine that separate Vite bootstrap with the CLI builder for the same specs. Match all plugin and compiler peer versions to the Angular version in `package.json`.

Files in this skill

  • eval-1.baseline.md2.6 KB
  • eval-1.with-skill.md2.7 KB
  • eval-2.baseline.md2.9 KB
  • eval-2.with-skill.md3.1 KB
  • eval-3.baseline.md2.6 KB
  • eval-3.with-skill.md2.8 KB
  • eval-4.baseline.md2.9 KB
  • eval-4.with-skill.md3.3 KB
  • eval-5.baseline.md3.1 KB
  • eval-5.with-skill.md3.4 KB
  • eval-6.baseline.md2.9 KB
  • eval-6.with-skill.md2.7 KB
  • trigger-1.md124 B
  • trigger-2.md143 B
  • trigger-3.md136 B
  • trigger-4.md132 B
  • trigger-5.md143 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.