angular-service-tests

Verify Angular service HTTP requests and public behavior in unit tests.

9|Updated Jan 18, 2025
One-click install
npx skills add https://github.com/TheNordicOne/ngx-formbar --skill angular-service-tests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: angular-service-tests
Source: https://github.com/TheNordicOne/ngx-formbar/tree/main/.claude/skills/angular-service-tests
Command: npx skills add https://github.com/TheNordicOne/ngx-formbar --skill angular-service-tests

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves flaky or incomplete Angular service tests by ensuring you validate service behavior and HTTP interactions in a consistent, maintainable way.

Core Features & Use Cases

  • Angular TestBed service setup: Inject and isolate the unit under test using TestBed without over-mocking.
  • HTTP request verification: Use HttpTestingController to assert expected URLs, methods, and payloads, and to fail on unexpected requests.
  • Dependency mocking strategies: Replace real dependencies with stubs or values while keeping tests focused on observable outcomes.
  • Use Case: When you have an Angular service that calls an API and transforms responses, use this skill to verify request correctness and ensure returned results match expectations.

Quick Start

Write or review your Angular *.spec.ts files by configuring TestBed with HttpClient testing, asserting requests with HttpTestingController, and ending each test with httpMock.verify().

Frequently Asked Questions about angular-service-tests

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

FAQPage Schema
How do I unit test an Angular service that makes HTTP calls?

Angular service HTTP testing uses HttpTestingController to assert expected URLs, methods, and payloads. You configure TestBed with HttpClientTesting, inject the service, and verify request correctness in your spec files.

What is the best way to mock dependencies in Angular service spec files?

Mocking dependencies in Angular spec files uses focused stubbing to replace only necessary dependencies with values while keeping tests targeted on observable outcomes, avoiding over-mocking.

Why does my Angular HTTP test suite report unverified requests?

Angular HTTP test suites report unverified requests when tests omit afterEach verification. Calling httpMock.verify() in afterEach ensures all expected HTTP interactions were matched and fails on unexpected requests.

Can I use TestBed to isolate a service without mocking all its dependencies?

TestBed can isolate a service without mocking all dependencies by applying focused stubbing to only the necessary dependencies, ensuring tests validate public service behavior without over-mocking.

When do I need HttpTestingController in Angular unit tests?

You need HttpTestingController in Angular unit tests when a service calls an API and transforms responses, allowing you to verify request correctness and ensure returned results match expectations.