angular-testing

Write unit and integration tests for Angular v21+ applications using Vitest or Jasmine.

Updated Aug 10, 2025
One-click install
npx skills add https://github.com/afonsoft/ai-studio-workspace --skill angular-testing-afonsoft
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: angular-testing
Source: https://github.com/afonsoft/ai-studio-workspace/tree/main/agents/skills/angular-testing
Command: npx skills add https://github.com/afonsoft/ai-studio-workspace --skill angular-testing-afonsoft

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires vitest, jsdom, and includes references (resource) components.

What problem does it solve? Testing modern Angular applications with signals, OnPush change detection, and standalone components requires updated patterns that older Jasmine/Karma guides do not cover, leaving developers unsure how to test signal-based code correctly. ## Core Features & Use Cases - Vitest and Jasmine Setup: Configure Angular v20+ native Vitest support via @angular/build, or use classic Jasmine with TestBed. - Signal-Aware Testing: Test signal inputs, computed values, httpResource, and OnPush components using setInput and explicit change detection. - Mocking and HTTP Testing: Mock services with vi.fn() or jasmine.createSpyObj, and verify HTTP calls with HttpTestingController. - Use Case: You are migrating a component to signal inputs and need tests that set inputs via fixture.componentRef.setInput, mock an injected service, and flush HTTP requests to verify rendered output. ## Quick Start Write a Vitest unit test for my standalone Angular component that uses signal inputs and mocks its injected User service.

Frequently Asked Questions about angular-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Angular signal-based components?▼

Test signal components by setting inputs with fixture.componentRef.setInput and mutating signals directly via .set() or .update(). Call fixture.detectChanges() after changes, then assert on computed values or rendered DOM output.

How to set up Vitest for Angular v20+ projects?▼

Install vitest and jsdom, then update angular.json to use the @angular/build:unit-test builder with your tsconfig.spec.json including vitest/globals types. Run tests with ng test, with optional --watch and --code-coverage flags.

Vitest vs Jasmine for Angular testing, which should I use?▼

Vitest offers faster execution with native ESM, instant watch feedback, and a built-in UI mode, while Jasmine with Karma is the traditional default. Angular v20+ supports Vitest natively, and migration maps jasmine.createSpy to vi.fn and spyOn to vi.spyOn.

How do I test HTTP requests in Angular services?▼

Provide provideHttpClient and provideHttpClientTesting in TestBed, inject HttpTestingController, then use expectOne to match the request URL and flush mock response data. Call httpMock.verify() in afterEach to ensure no outstanding requests remain.

Why does my OnPush component test not update the template?▼

OnPush components require explicit change detection in tests. Set signal inputs with fixture.componentRef.setInput and call fixture.detectChanges() after each update so the template re-renders with the new values.

Can I test Angular router navigation and guards in unit tests?▼

Yes, use RouterTestingHarness with provideRouter to navigate by URL and assert on the activated component. For guards, mock the authentication service and verify that navigation succeeds or redirects based on the guard result.