angular-testing

Solid

Write Angular component tests using TestBed, ComponentHarness, and HttpTestingController with proper signal input handling. Use when writing component tests, mocking HTTP calls, or testing signal inputs. (triggers: **/*.spec.ts, TestBed, ComponentFixture, TestHarness, provideHttpClientTesting)

Testing & QA 505 stars 148 forks Updated yesterday Apache-2.0

Install

View on GitHub

Quality Score: 88/100

Stars 20%
90
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
68
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Testing ## **Priority: P1 (HIGH)** ## 1. Query via Component Harnesses - Always use `ComponentHarness` (e.g., `MatButtonHarness`) instead of CSS selectors — harnesses are stable across DOM changes. See [harness pattern](references/harness-pattern.md) for ComponentHarness examples. ## 2. Mock HTTP with HttpTestingController - Use `provideHttpClientTesting()` instead of manual HttpClient mocks. - Call `expectOne`, `.flush(mockData)`, and `verify()` in `afterEach`. See [harness pattern](references/harness-pattern.md) for HttpTestingController examples. ## 3. Test Signal Inputs Correctly - Use `fixture.componentRef.setInput('name', value)` — do NOT assign directly. - Call `fixture.detectChanges()` after `setInput()`. - Signals update synchronously — `fakeAsync` is usually not needed. ## 4. Choose Your Test Runner - Angular v20+ supports **Vitest** natively via `@angular/build:unit-test`. Faster, native ESM, no Karma needed. - Jasmine/Karma still supported for existing projects. ## Anti-Patterns - **No DOM CSS selectors**: Query via `ComponentHarness`, not CSS class strings. - **No manual HttpClient mock**: Use `provideHttpClientTesting()` + `HttpTestingController`. - **No direct @Input() assignment**: Use `fixture.componentRef.setInput()` for signal inputs. ## References - [Harness Pattern](references/harness-pattern.md)

Details

Author
HoangNguyen0403
Repository
HoangNguyen0403/agent-skills-standard
Created
4 months ago
Last Updated
yesterday
Language
TypeScript
License
Apache-2.0

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category