skills/testing/SKILL.md
Guide for writing comprehensive, well-structured tests with full coverage. Use when creating test files, adding tests to existing files, reviewing test coverage, or when asked to write, fix, or expand tests. Covers test organization (flat vs nested), coverage categories (happy/sad/edge), .todo patterns for planned tests, and formatting conventions.
npx skillsauth add macieklamberski/kvalita testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Detect the test library from project (bun:test, vitest, jest, etc.) and use its idioms. Never assume a specific framework.
For general code formatting rules (arrow functions, naming, exports, etc.), see the formatting skill.
*.test.ts naming (not *.spec.ts)__tests__/ directories)helpers/urls.ts → helpers/urls.test.tsFlat — for pure/simple functions (parsers, validators, formatters):
describe('functionName', () => {
it('should return X with valid input', () => {})
it('should return undefined for empty string', () => {})
})
Nested 3-category — for complex functions (DB operations, API handlers, side effects):
describe('functionName', () => {
describe('happy paths', () => {
it('should create record with all fields', () => {})
it('should create record with minimal fields', () => {})
})
describe('sad paths', () => {
it('should throw NotFoundError when record missing', () => {})
})
describe('edge cases', () => {
it('should handle duplicate operation idempotently', () => {})
})
})
When to use which:
Happy paths — normal successful operations:
Sad paths — expected failures:
Edge cases — boundary conditions:
For every function, consider:
Implement the most critical tests first (happy paths). Use .todo for the rest.
const expected: Array<MyType> = [...] instead of as const. Explicit type annotations keep arrays mutable (avoiding readonly conflicts with matchers) while still narrowing literal/discriminated union types."foo"/"bar". Include only data relevant to the specific test.For detailed guidance on mocking, isolation, data patterns, and common anti-patterns, see references/best-practices.md.
Use it.todo for planned but unimplemented tests. Every .todo MUST include a comment inside the callback body explaining the scenario:
// Simple scenario — single sentence.
it.todo('should preserve existing title when feed title is null', () => {
// Feed has null title — channel should keep its existing title.
})
// Complex scenario — multi-line with setup and expected behavior.
it.todo('should timeout when headers delayed beyond maxTimeout', () => {
// Server delays sending headers for 16+ seconds (> maxTimeout: 15s).
// Expected: ETIMEDOUT error after ~15 seconds, retry triggered,
// after 3 retries throw UnreachableUrlError.
})
Use describe.todo for entire groups of planned tests:
describe.todo('error handling', () => {
it.todo('should throw on invalid URL', () => {
// Pass malformed URL like 'not-a-url' or 'ht!tp://bad'.
// Expected: URL parse error before safety check runs.
})
})
Guidelines:
.todo without a commentit.todo.todo sad paths and edge cases when not immediately criticalFor detailed rules on variable naming, spacing, assertions, object formatting, and test ordering, see references/formatting.md.
development
Code formatting and style rules not handled by auto-formatters (Biome/Prettier). Use when writing or modifying code files. Covers function declarations, exports, types, comments, JSX, and naming conventions.
development
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.
development
Maintainer workflow for OpenClaw releases, prereleases, changelog release notes, and publish validation. Use when Codex needs to prepare or verify stable or beta release steps, align version naming, assemble release notes, check release auth requirements, or validate publish-time commands and artifacts.
development
Run, watch, debug, and extend OpenClaw QA testing with qa-lab and qa-channel. Use when Codex needs to execute the repo-backed QA suite, inspect live QA artifacts, debug failing scenarios, add new QA scenarios, or explain the OpenClaw QA workflow. Prefer the live OpenAI lane with regular openai/gpt-5.4 in fast mode; do not use gpt-5.4-pro or gpt-5.4-mini unless the user explicitly overrides that policy.