agentsclimarketplace

Testing patterns

Skill dkmqflx/claude-tools/.claude/skills/testing-patterns

Vitest testing patterns for this project. Automatically applied when writing unit/integration tests for components, custom hooks, Server Actions, and utility functions.From its SKILL.md

Install
npx -y skills add dkmqflx/claude-tools --skill testing-patterns

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

2.8 KB, 605 tokens by cl100k_base, as published. Nobody here has run it

Testing Patterns

Boilerplate → template.md | Full example → examples/sample.md | Validate → scripts/validate.sh

Setup

  • Framework: Vitest + jsdom
  • File location: src/features/{name}/test/*.test.{ts,tsx}
  • Setup file: src/shared/test/setup.ts — global vi.mock("zustand"), vi.clearAllMocks() in afterEach
  • Libraries: @testing-library/react, @testing-library/user-event

What to Test

TargetTypeKey rule
Pure UI components (no state/logic)SkipNo value — visual tools (Storybook) instead
Simple child componentsSkipCovered by parent's integration test
Pure functions, utilsUnitNo external dependencies; used widely → stability matters
Custom hooksUnitrenderHook, mock next/navigation
Components with API/state/contextIntegrationWire real stores/hooks, mock only externals
Server Action / ServiceIntegrationMock Firebase Admin, mock external APIs

Rules

What & how to test

  • Test interfaces and behavior (what the user sees in the UI), not internal implementation details
  • Internal state/variable assertions → brittle tests coupled to implementation; prefer UI assertions
  • One it() = one behavior — SRP applies to tests too
  • Write meaningful tests: ask "what would break if this logic changes?" not "how do I hit 100% coverage"
  • Prefer UI assertions (getByRole, getByText, getByTestId) over Store.getState() in component tests

Mocking

  • Mock externals only: Firebase, TanStack Query hooks, Next.js navigation
  • Minimize mocking — excessive mocks reduce reliability and create tests that pass when production breaks
  • Business logic (state management, API calls) should be cohesive in the parent component — mock at that boundary
  • Split integration tests by business logic domain; don't combine unrelated domains in one test
  • Always use vi.hoisted() for mock references needed before vi.mock() calls
  • Rely on vi.clearAllMocks() from setup.ts; explicitly reset mocks with specific return values in beforeEach

Style

  • Always use userEvent, never fireEvent
  • it descriptions follow "should ... when ..." pattern
  • Group related cases in describe blocks
  • Factory functions for repeated fixture data

File Location

src/features/{name}/
  test/
    {ComponentName}.test.tsx     # component integration tests
    {hookName}.test.ts           # custom hook unit tests
    {fileName}.test.ts           # service/action tests
    {utilName}.test.ts           # pure function unit tests

What ships with it: 3 files

10.9 KB alongside SKILL.md, 1 of them executable

examples/

scripts/

Keep looking

Skills are one crate of 326,758. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.