GravionLabs/elysion / .agents/skills/ng-test
ng-test
VerifiedAngular test rules with Vitest and TestBed (components, signals, mocking, async). Use when writing or running tests in Angular.
Prerequisites
- Project root with
angular.json; Angular 21+ with standalone components - Vitest, either via
vitest.config.tsat the root (as set up byng-create-project) or via the Angular CLI's built-in Vitest builder
Test Runner
- Framework: Vitest for Angular v21+ (replaces Karma/Jasmine); Jest for Angular v20 and earlier
- Run all:
<pm> test(package manager fromdetect-techstack); projects using the CLI builder without a config file runng test - Run single:
npx vitest run <path>, orng test --include <path>with the CLI builder - Targeted run (per commit):
npx vitest run <paths>for the spec files of the changed paths, orng test --include <path>with the CLI builder; unknown mapping: the project's fast/unit script
Component Testing
import { TestBed } from '@angular/core/testing';
import { My } from './my';
describe('My', () => {
beforeEach(() => TestBed.configureTestingModule({ imports: [My] }));
it('renders with input', () => {
const fixture = TestBed.createComponent(My);
fixture.componentRef.setInput('value', 'test');
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toContain('test');
});
});
TestBed rules
TestBed.configureTestingModule()for component/service wiring; onedescribeper component/service- Use
fixture.debugElement.query(By.css(...))for DOM queries - Call
fixture.detectChanges()after state changes;TestBed.flushEffects()when testing signal effects; code that callsinject()needsTestBed.runInInjectionContext
Gotchas
- Use
provideHttpClient(withFetch())for HTTP testing - Async operations (zoneless, Angular 21):
vi.useFakeTimers()for timers,await fixture.whenStable()for pending work;fakeAsync/tick()only when the project still uses zone.js - Set signal inputs with
fixture.componentRef.setInput('name', value)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |