agentleFS
nexuslabs-ainexuslabs-ai/nxds/.claude/skills/implement-test-guide/SKILL.md

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.

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
  1. Distinctive:

    Always load and follow:

    line 52
  2. Distinctive:

    Use real data patterns from the codebase — real seed colours, real component source, genuine user flows

    line 96
  3. Very specific:

    Never mock nxds's own functions

    line 103
  4. Distinctive:

    Create the real inputs the assertions need

    line 109
  5. Distinctive:

    Use partial matching for complex objects

    line 116
  6. Distinctive:

    After test implementation is complete:

    line 169

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

SourceDetectionHow to Extract
Testing plan.md file with test planRead the file content
GitHub issue#123 pattern in inputgh issue view 123 --json number,title,body,labels,state,url
Source codeFile path to code to testRead the source file
ConversationRequirements in chatParse 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:

TargetDetect ByTesting Approach
React componentspackages/react/src/components/Story-first: play functions in *.stories.tsx
Core enginepackages/core/src/lib/Vitest behaviour tests — thresholds and invariants, never snapshots
cn mergepackages/react/src/lib/utils.tsVitest, in utils.test.ts
ESLint rulespackages/eslint-plugin/RuleTester valid/invalid cases in __tests__/
React ↔ Vue parityparity/Vitest, comparing the two packages with each other
CLIpackages/cli/src/Vitest in packages/cli/__tests__/: run the CLI on a throwaway app
Apps, scripts, hooksapps/, scripts/, packages/*/scripts/, hooks/No tests — stop and tell the user

Base Rules

Always load and follow:

RulePurpose
code-quality.mdGoverning principle: favor simplicity over cleverness; index to per-rule files
ripple-effect.mdTest additions must leave helpers, fixtures, and adjacent tests consistently updated
guard-clauses.mdKeep the assertion path at column 0; exit early on setup failures
logging-proportionality.mdOne dense canonical log line beats ten incremental ones
code-comments.mdComment only non-obvious logic; no rationale blocks; TODOs require tracked issues
project-stage.mdPre-production: no backcompat, no shims, no feature flags — change code in place
docs-mcp.mdMANDATORY: query nxds-docs-mcp for any third-party API; do not guess from memory
github.mdPR title/body templates, branch naming, commit format, Closes #N

Implementation Process

Phase 1: Understand What to Test

  1. 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
  2. Understand the code behavior:
    • What are the inputs?
    • What are the expected outputs?
    • What are the error cases?
    • What are the edge cases?
  3. 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

  1. 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.
  2. Design inputs:
    • Use real data patterns from the codebase — real seed colours, real component source, genuine user flows
    • Cover happy path, errors, edge cases
  3. 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

Phase 3: Implement Tests

  1. 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
  2. Follow testing principles:
    • Assert on results, not implementation
    • Use partial matching for complex objects
    • One assertion focus per test
    • Descriptive test names
  3. 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

  1. Run tests:

    pnpm test                    # All tests
    pnpm test path/to/test.ts   # Specific file
  2. Verify quality:
    • Tests actually fail when code is broken
    • Tests are deterministic (run multiple times)
    • No flaky behavior
    • Error cases covered
  3. 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

FrameworkUse CaseImport Pattern
VitestUnit testsimport { describe, it, expect } from 'vitest'
StorybookComponent testsimport { expect, fn, userEvent, within } from 'storybook/test'

Principles to Follow

  1. Result validation over coverage — Good assertions matter more than line count
  2. Real inputs — Use actual data patterns from the system
  3. Partial matching — Assert on what matters, not everything
  4. Stub the browser, not nxds — Replace an API the runner lacks; never mock nxds's own functions
  5. Determinism — Tests must produce same result every time
  6. One focus per test — Each test should have one reason to fail
  7. Readable tests — Test code is documentation

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.