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
npx -y skills add dkmqflx/claude-tools --skill testing-patternsAssembled 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— globalvi.mock("zustand"),vi.clearAllMocks()in afterEach - Libraries:
@testing-library/react,@testing-library/user-event
What to Test
| Target | Type | Key rule |
|---|---|---|
| Pure UI components (no state/logic) | Skip | No value — visual tools (Storybook) instead |
| Simple child components | Skip | Covered by parent's integration test |
| Pure functions, utils | Unit | No external dependencies; used widely → stability matters |
| Custom hooks | Unit | renderHook, mock next/navigation |
| Components with API/state/context | Integration | Wire real stores/hooks, mock only externals |
| Server Action / Service | Integration | Mock 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) overStore.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 beforevi.mock()calls - Rely on
vi.clearAllMocks()from setup.ts; explicitly reset mocks with specific return values inbeforeEach
Style
- Always use
userEvent, neverfireEvent itdescriptions follow "should ... when ..." pattern- Group related cases in
describeblocks - 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/
- sample.md4.6 KB
scripts/
- validate.shruns1.9 KB
- template.md4.4 KB