Skillshub angular-testing
Standards for Component Test Harnesses and TestBed. Use when writing Angular component tests with TestBed or Component Harnesses. (triggers: **/*.spec.ts, TestBed, ComponentFixture, TestHarness, provideHttpClientTesting)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/angular-testing" ~/.claude/skills/comeonoliver-skillshub-angular-testing && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/angular-testing/SKILL.mdsource content
Testing
Priority: P1 (HIGH)
Principles
- Harnesses: Always use ComponentHarness (e.g., MatButtonHarness or custom ones) to interact with components via getHarness. Never query by CSS class or DOM/CSS selectors in tests — harnesses are stable and don't break when CSS classes change. Wait for await button.click() or similar calls.
- Provider Mocks: Use provideHttpClientTesting() instead of mocking
manually. Inject HttpTestingController to use expectOne,HttpClient
, and verify() in afterEach. Never mock HttpClient directly..flush(mockData) - Signal Testing: Signals update synchronously — no fakeAsync needed usually.
Test Runner
Angular v20+ supports Vitest natively via
@angular/build:unit-test builder in angular.json. Vitest is recommended for new projects as it is faster, native ESM, and no Karma needed. Jasmine/Karma still supported.
Signal Input Testing
Use fixture.componentRef.setInput('name', value) to set signal inputs in tests — do NOT assign component.name = value directly — this doesn't work for signal inputs. After setInput() call fixture.detectChanges() to trigger re-render.
Guidelines
- Avoid logic: Tests should just assert inputs and outputs.
- Spectator: Consider using libraries like
for cleaner boilerplate if allowed.@ngneat/spectator - Standalone: Import the standalone component directly in
.TestBed.configureTestingModule({ imports: [MyComponent] })
Anti-Patterns
- No DOM CSS selectors: Query via
, not CSS class strings.ComponentHarness - No manual HttpClient mock: Use
+provideHttpClientTesting()
.HttpTestingController - No @Input() in tests: Use
for signal inputs.fixture.componentRef.setInput()