/omniagents-typescript:testingfrom omniagents-typescript
Use when writing or reviewing TypeScript tests: Vitest 4 suite architecture and projects config, typed mocks and vi.fn / vi.spyOn / vi.mock choices, MSW at the network boundary, fake timers and async assertion ordering, flaky or order-dependent tests, Testing Library component tests, fast-check property-based tests, expectTypeOf type-level tests, testcontainers integration suites, snapshots, coverage thresholds, or vitest.config / ESLint test-rule configuration.
Ships in omniagents-typescript. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A test earns its place by failing when the behavior it protects breaks. Every
rule below serves that property: a suite where each test kills a specific
wrong implementation, and where red always means a real defect — never a
flake, never a stale mock, never an ordering accident. Tests are production
code: they compile under the same tsc --strict project, they pass the same
type-aware ESLint config as src/, and they are reviewed against the same
bar. The typings skill's rules — no any, no bare @ts-ignore,
satisfies over as — apply inside test files without exemption.
This skill assumes Vitest 4+ on TypeScript 6.0+, with MSW 2 at the
network boundary, Testing Library + user-event for components, fast-check
for property-based tests, testcontainers for integration infrastructure, and
@vitest/eslint-plugin for test-specific lint rules. For version-sensitive
behavior, query Context7 MCP or the official docs before changing a rule.
This skill is rules, not a tutorial. It assumes familiarity with describe
/ it, vi mocking, and async testing. Scope boundaries:
test-driven-development
skill governs the workflow; this skill governs what the tests look like.typings skill.mount() fixture — but this
skill still prefers Testing Library/jsdom for component tests: speed,
hermeticity, and the Testing Library query discipline this skill already
teaches. Playwright CT is the option when a real browser is required; see
references/components.md.src/. Test files are included in the
type-checked project (tsc --noEmit covers them) and in the type-aware
ESLint run. No any in test data — builders with satisfies instead of
casts; no @ts-expect-error without an error code and reason (the one
sanctioned use: negative type tests — see references/unit.md).await expect(promise).rejects. toThrowError(...) — an unawaited .rejects is a test that passes before
its assertion runs. @typescript-eslint/no-floating-promises stays on for
test files precisely because of this failure mode.restoreMocks: true,
mockReset: true, unstubEnvs: true, unstubGlobals: true in
vitest.config.ts — a manual afterEach(() => vi.restoreAllMocks()) in
each file is the version of this that one file forgets. The pairing is
mandatory: in Vitest 4, restoreMocks only restores spies created with
vi.spyOn and no longer resets mock state, so vi.fn() call history and
mockResolvedValueOnce queues leak between tests unless mockReset (or
clearMocks) is also set. Fake timers are the exception:
vi.useFakeTimers() is paired with vi.useRealTimers() in afterEach
in the same file, because timer state is not covered by restoreMocks.onUnhandledRequest: "error" — an unexpected request is a failure, not a
passthrough), no real timer waits (fake timers advanced explicitly), no
wall-clock reads (vi.setSystemTime or an injected clock), no unseeded
randomness (seeded generators injected; fc manages its own seeds and
reports them). TZ is pinned to UTC in config so date tests do not pass
only in your timezone. Retrying flaky tests is rejected as a fix.sequence.shuffle enabled. No test reads module state another test
wrote; shared module-level state in the subject is reset via a designed
seam, not vi.resetModules() folklore.describe(subject) + behavior sentence:
it("rejects without retrying on 4xx", ...). Arrange, act, assert
separated by blank lines; no branching or loops around assertions — a
loop over cases is a test.each table that lost its names..only (Vitest
defaults allowOnly to false in CI); vitest/no-focused-tests catches it
at lint time before CI spends the minutes. .skip carries a reason.expect(client.push).toHaveBeenCalled() alone survives pushing the wrong
payload; assert the payload. Exception: when the interaction is the
contract ("submits the trimmed name to onSubmit"), assert the call
exactly — count and arguments.src/testing/ utilities, not on the class under test.Layer by what can falsify the behavior: pure logic and services with
injected fakes → unit (node environment); components → Testing Library in
the jsdom/browser project; route handlers with a real database →
integration behind a separate Vitest project and CI job. Do not re-prove
unit-tested logic through the component layer. Vitest projects — renamed
from workspace in Vitest 3.2; Vitest 4 removed the old name — encode the
layers so environment choices are structural, not per-file pragmas. Test
through the public import path, ship every bugfix with its regression pin,
and keep shared typed builders in src/testing/. Full rules:
references/unit.md.
| Symptom or question | Read |
|---|---|
Should this Vitest suite mock the repository layer? DI vs vi.mock vs MSW | references/doubles-and-boundaries.md |
| Which double — stub, fake, spy, mock — and what never gets mocked | references/doubles-and-boundaries.md |
Fake timers wedge fetch; retry/debounce/backoff tests; real-timer waits | references/determinism.md |
| Env vars, globals, filesystem, or module singletons leak between tests | references/determinism.md |
getByTestId everywhere; query priority; user-event; vitest-axe | references/components.md |
| Playwright component testing vs Testing Library/jsdom | references/components.md |
Mock state leaks despite restoreMocks | Non-negotiables above + references/gates-and-ci.md |
When to reach for fast-check; pinning counterexamples; fc.commands | references/property-based.md |
| Layering, public import path, test data builders, assertions, snapshots | references/unit.md |
expectTypeOf / *.test-d.ts type-level tests | references/unit.md |
| testcontainers, real HTTP layer, vendor emulators, Pact contract tests | references/integration.md |
Coverage thresholds, vitest.config.ts / ESLint reference, the CI stack | references/gates-and-ci.md |
vi.mock on the subject's own module or internals,
then asserting the mock was called — only glue is covered.expect(p).rejects.toThrow(...) without
await — the test ends before the assertion runs.await new Promise((r) => setTimeout(r, 500)) —
green locally, red on loaded CI. Deadline-bounded waitFor or fake
timers.restoreAllMocks in afterEach across
files instead of config — the file that forgets leaks spies suite-wide.{ ok: false, status: 500 } standing in
for Response — drifts from the contract the day a header is read.any-typed builders and as User casts in test data — the test can
feed the subject values production types forbid.-u.retry: config or rerun actions instead of removing
the nondeterminism source. The flake is a bug — in the test or the code.vi.mock vs MSW → injectable parameter → typed fake, no
mocking machinery. Network boundary → MSW. Module you cannot inject and
cannot reach over the wire → vi.mock with importOriginal, last
resort.test.each vs fast-check → enumerable meaningful cases → test.each
with named cases; invariant over a domain → fast-check, with
counterexamples pinned back into test.each.vi.waitFor → subject schedules time (retry,
debounce, TTL) → fake timers with boundary advances; genuinely
concurrent completion → waitFor/findBy* with deadline.toStrictEqual vs toMatchObject) live in
references/unit.md; clock choices (vi.setSystemTime vs injected
clock) in references/determinism.md.test-driven-development (where installed); this skill
defines the quality bar of the artifacts that process produces.mount() fixture — is the
sanctioned route when a component test needs a real browser, while
Testing Library/jsdom stays the default for speed, hermeticity, and its
query discipline; references/components.md draws the line.vitest.config.ts and eslint.config.* are; the reference
blocks in references/gates-and-ci.md are the shape to converge on.This skill is project policy, not a complete upstream reference. Package
versions cited across this skill were verified 2026-07-26; each file under
references/ carries its own freshness note. When applying it to
unfamiliar APIs or version-sensitive behavior (Vitest config keys, MSW
handler forms, coverage semantics), verify against primary docs — prefer
Context7 MCP; otherwise web search restricted to official sources.
projects, fake
timers, mocking, --typecheck, coverage.workspace → projects (renamed in Vitest 3.2; Vitest 4 removed the
old name), coverage include semantics, restoreMocks narrowing.setupServer, handler overrides,
onUnhandledRequest.references/components.md (opens in a new tab)references/determinism.md (opens in a new tab)references/doubles-and-boundaries.md (opens in a new tab)references/gates-and-ci.md (opens in a new tab)references/integration.md (opens in a new tab)references/property-based.md (opens in a new tab)references/unit.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Trigger for *.test.ts(x) / *.test-d.ts files, vitest.config.*, writing unit or integration tests, adding a regression test for a bugfix, test-only diffs, flaky tests, real setTimeout waits in tests, unawaited expect().rejects, unseeded randomness, vi.mock vs dependency injection decisions, mock restore/reset hygiene, jsdom vs node environment choices, snapshot bloat, coverage thresholds, vi.stubEnv / vi.stubGlobal isolation, vi.hoisted mock setup, test data builders, Pact contract testing, vitest-axe accessibility, or ESLint rules for test files.
npx claudepluginhub gao-hongnan/omniagents --plugin omniagents-typescript4 skills in this plugin
/docstringsUse when writing or reviewing TypeScript API documentation for exported modules, classes, functions, methods, types, interfaces, properties, TSDoc tags, TypeDoc output, compile-checkable examples, or JSDoc interop in legacy JavaScript./library-patternsUse when writing or reviewing TypeScript that wraps a network service or authors a client SDK: client construction, per-request options, retry policy with maxNetworkRetries, idempotency keys, `APIError` hierarchies, structured outputs via `zodResponseFormat` / `zodTextFormat`, streaming with AbortController, cursor pagination, or telemetry hooks./typingsOther plugins' skills for the same job