implement-test-guide
Skill4 starsChanged 15 days agoMITView on GitHub
Implement tests with production-quality coverage. Use when implementing test suites, adding test coverage, or building testing infrastructure.
In this repository25 other files it gives its agents.
- AGENTS.mdAGENTS.md
- analyze-deps-guideSkill
- design-planSkill
- docs-writingSkill
- frontend-designSkill
- implement-guideSkill
- implement-test-guideSkill
- modern-web-guidanceSkill
- pr-fix-guideSkill
- pr-review-follow-upSkill
- pr-review-guideSkill
- shadcn-adapt-guideSkill
- shadcnSkill
- ui-audit-guideSkill
- analyze-deps-guideSkill
- design-planSkill
- docs-writingSkill
- frontend-designSkill
- implement-guideSkill
- pr-fix-guideSkill
- pr-review-follow-upSkill
- pr-review-guideSkill
- shadcn-adapt-guideSkill
- shadcnSkill
- ui-audit-guideSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 52
Always load and follow:
- Distinctive: line 96
Use real data patterns from the codebase — real seed colours, real component source, genuine user flows
- Very specific: line 103
Never mock nxds's own functions
- Distinctive: line 109
Create the real inputs the assertions need
- Distinctive: line 116
Use partial matching for complex objects
- Distinctive: line 169
After test implementation is complete:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Implement Test
Purpose
Implement tests with a focus on result validation over code coverage. Works with any codebase, any testing framework, using the "given input → expect output" philosophy.
When to Use
- Implementing tests for new or existing code
- Adding coverage to code that falls inside
.claude/rules/testing.md§ Scope
Context Sources
This skill works with multiple input types:
| Source | Detection | How to Extract |
| Testing plan | .md file with test plan | Read the file content |
| GitHub issue | #123 pattern in input | gh issue view 123 --json number,title,body,labels,state,url |
| Source code | File path to code to test | Read the source file |
| Conversation | Requirements in chat | Parse from conversation history |
Package-Specific Testing Patterns
nxds tests only six kinds of thing — see .claude/rules/testing.md § Scope. Based on what you're testing:
| Target | Detect By | Testing Approach |
| React components | packages/react/src/components/ | Story-first: play functions in *.stories.tsx |
| Core engine | packages/core/src/lib/ | Vitest behaviour tests — thresholds and invariants, never snapshots |
cn merge | packages/react/src/lib/utils.ts | Vitest, in utils.test.ts |
| ESLint rules | packages/eslint-plugin/ | RuleTester valid/invalid cases in __tests__/ |
| React ↔ Vue parity | parity/ | Vitest, comparing the two packages with each other |
| CLI | packages/cli/src/ | Vitest in packages/cli/__tests__/: run the CLI on a throwaway app |
| Apps, scripts, hooks | apps/, scripts/, packages/*/scripts/, hooks/ | No tests — stop and tell the user |
Base Rules
Always load and follow:
| Rule | Purpose |
| code-quality.md | Governing principle: favor simplicity over cleverness; index to per-rule files |
| ripple-effect.md | Test additions must leave helpers, fixtures, and adjacent tests consistently updated |
| guard-clauses.md | Keep the assertion path at column 0; exit early on setup failures |
| logging-proportionality.md | One dense canonical log line beats ten incremental ones |
| code-comments.md | Comment only non-obvious logic; no rationale blocks; TODOs require tracked issues |
| project-stage.md | Pre-production: no backcompat, no shims, no feature flags — change code in place |
| docs-mcp.md | MANDATORY: query nxds-docs-mcp for any third-party API; do not guess from memory |
| github.md | PR title/body templates, branch naming, commit format, Closes #N |
Implementation Process
Phase 1: Understand What to Test
Identify the target:
If testing plan provided → Read and understand requirements If source file provided → Read and understand the code If GitHub issue (#123) → Fetch issue via gh issue view Otherwise → Clarify with user what needs tests- Understand the code behavior:
- What are the inputs?
- What are the expected outputs?
- What are the error cases?
- What are the edge cases?
- Identify existing test patterns:
- How does this codebase test similar code?
- What test utilities exist?
- What's the test file naming convention?
Phase 2: Design Test Strategy
- Pick the kind from the Package-Specific Testing Patterns table above. If the code is not in one of the five rows, it gets no test — stop and tell the user. There is no integration, e2e, or snapshot tier to fall back on.
- Design inputs:
- Use real data patterns from the codebase — real seed colours, real component source, genuine user flows
- Cover happy path, errors, edge cases
- Stub only what the environment lacks:
- Replace a browser API the runner has no implementation of (e.g.
matchMedia) - Never mock nxds's own functions
- Replace a browser API the runner has no implementation of (e.g.
Phase 3: Implement Tests
- Work through systematically:
- Set up test file and imports
- Create the real inputs the assertions need
- Implement happy path tests
- Implement error case tests
- Implement edge case tests
- Follow testing principles:
- Assert on results, not implementation
- Use partial matching for complex objects
- One assertion focus per test
- Descriptive test names
Test file structure:
import { describe, it, expect } from 'vitest'; // or appropriate framework describe('ModuleName', () => { describe('functionName', () => { it('returns expected output for valid input', () => { // Arrange const input = createFixture(); // Act const result = functionName(input); // Assert expect(result.success).toBe(true); expect(result.data).toMatchObject({ expectedField: 'value', }); }); it('returns error for invalid input', () => { // Error case test }); }); });
Phase 4: Verify Tests
Run tests:
pnpm test # All tests pnpm test path/to/test.ts # Specific file- Verify quality:
- Tests actually fail when code is broken
- Tests are deterministic (run multiple times)
- No flaky behavior
- Error cases covered
- Check test output:
- Clear failure messages
- Easy to understand what failed and why
Output Format
After test implementation is complete:
## Tests Implemented
### Target
{What was tested - module/component/feature}
### Test Files
| File | Tests | Description |
| ------------------------ | ----- | ----------------------------- |
| `path/to/module.test.ts` | 5 | Unit tests for core functions |
### Coverage
| Scenario | Tests | Status |
| ----------- | ----- | ------ |
| Happy path | 3 | ✅ |
| Error cases | 2 | ✅ |
| Edge cases | 2 | ✅ |
### Key Test Patterns
{Notable patterns used - real inputs, assertions, play-function flow}
### Verification
```bash
pnpm test path/to/tests
```
- [ ] All tests passing
- [ ] Tests are deterministic
- [ ] Error cases covered
### Next Steps
{Any follow-up items or notes}Assertion Patterns Reference
Partial Object Matching
// Good - checks relevant fields
expect(result).toMatchObject({
success: true,
data: { name: 'Button' },
});
// Good - custom helper for domain objects
expectPropsToInclude(result.props, [{ name: 'variant', type: 'string' }]);Array Assertions
// Good - checks contents without order dependency
expect(result.items).toContain('expected-item');
expect(result.items).toHaveLength(3);
// Good - checks structure
expect(result.items).toEqual(
expect.arrayContaining([expect.objectContaining({ id: 'item-1' })])
);Error Assertions
// Good - checks error type and message
await expect(doThing()).rejects.toThrow('specific error');
// Good - checks error shape
const result = await doThing();
expect(result.success).toBe(false);
expect(result.error.code).toBe('VALIDATION_ERROR');Common Testing Frameworks
| Framework | Use Case | Import Pattern |
| Vitest | Unit tests | import { describe, it, expect } from 'vitest' |
| Storybook | Component tests | import { expect, fn, userEvent, within } from 'storybook/test' |
Principles to Follow
- Result validation over coverage — Good assertions matter more than line count
- Real inputs — Use actual data patterns from the system
- Partial matching — Assert on what matters, not everything
- Stub the browser, not nxds — Replace an API the runner lacks; never mock nxds's own functions
- Determinism — Tests must produce same result every time
- One focus per test — Each test should have one reason to fail
- Readable tests — Test code is documentation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

