angular-testing_skill

This skill helps you write Angular unit tests with Vitest and TestBed using practical templates and patterns beside source files.
  • TypeScript

21

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill danielsogl/copilot-workflow-demo --skill angular-testing

  • SKILL.md6.1 KB

Overview

This skill helps you write unit tests for Angular components, services, pipes, and directives using Vitest and Angular TestBed patterns. It provides templates, import guidance, and common patterns for mocking, async code, fake timers, and DOM queries to create consistent, reliable specs. Use it to produce test files colocated with source code and follow project conventions.

How this skill works

The skill generates test templates and explains what to import, how to configure TestBed, and how to provide zoneless change detection. It covers component, service, and directive testing patterns: creating fixtures, injecting services, mocking dependencies with vi, verifying HTTP calls with HttpTestingController, and asserting DOM state via debugElement and By. It also documents signal inputs, outputs, async handling, and fake timers.

When to use it

  • When you need to create or update a .spec.ts file next to a source file
  • When writing unit tests for Angular components, services, pipes, or directives
  • When you want consistent Vitest patterns and TestBed configuration
  • When you need examples for mocking services, HTTP requests, or external modules
  • When testing inputs, outputs, signals, or DOM interactions

Best practices

  • Place spec files alongside source files (component-name.spec.ts next to component-name.ts)
  • Use provideZonelessChangeDetection() in providers to keep tests deterministic
  • Follow AAA (Arrange, Act, Assert) and give tests descriptive names
  • Mock external dependencies with vi.mock or provide value mocks via TestBed
  • Verify HTTP expectations with HttpTestingController.verify() in afterEach

Example use cases

  • Generate a component test that asserts rendering and button click behavior
  • Create a service test that asserts an HTTP GET and flushes mock data
  • Mock a dependency service to return synchronous or async values for a component
  • Test a component signal input by setting the input before detectChanges
  • Verify an EventEmitter output by subscribing to the emitter and asserting calls

FAQ

No. Vitest globals are preconfigured in tsconfig.spec.json and available without imports.

How should I test HTTP calls in services?

Provide provideHttpClientTesting(), inject HttpTestingController, assert the request via expectOne, then flush mock data and call httpMock.verify() in afterEach.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational