agentsclimarketplace

Angular testing

Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/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)From its SKILL.md

Install
npx -y skills add ComeOnOliver/skillshub --skill angular-testing

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

2.1 KB, 433 tokens by cl100k_base, as published. Nobody here has run it

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 HttpClient manually. Inject HttpTestingController to use expectOne, .flush(mockData), and verify() in afterEach. Never mock HttpClient directly.
  • Signal Testing: Signals update synchronouslyno 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 @ngneat/spectator for cleaner boilerplate if allowed.
  • Standalone: Import the standalone component directly in TestBed.configureTestingModule({ imports: [MyComponent] }).

Anti-Patterns

  • No DOM CSS selectors: Query via ComponentHarness, not CSS class strings.
  • No manual HttpClient mock: Use provideHttpClientTesting() + HttpTestingController.
  • No @Input() in tests: Use fixture.componentRef.setInput() for signal inputs.

References

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.