safe-action-testing — Claude Code skill: next-safe-action tests
Tells the agent how to write Vitest tests for next-safe-action actions and hooks: validation, middleware, server errors.
npx skills add next-safe-action/skills --skill safe-action-testing -a claude-codeWhat safe-action-testing does
The skill kicks in when you ask for tests around next-safe-action. Your agent gets Vitest patterns for calling a server action directly and asserting on result.data, validationErrors and serverError, plus a section on actions that take bind arguments.
Middleware and hooks have their own parts. For middleware you build a client with a specific chain and stub the session with vi.mock; for hooks the skill uses renderHook from React Testing Library and checks isIdle, isExecuting, hasSucceeded, then calls reset. The helpers flattenValidationErrors and formatValidationErrors are covered, and there is a mock for next/navigation so redirects can be tested.
Bind-argument failures arrive as ActionBindArgsValidationError, so a test has to use rejects.toThrow() instead of reading result.validationErrors. The digest strings on NEXT_REDIRECT are a Next.js internal, and the skill itself flags that they shift between versions.
What it helps with
- write tests for a next-safe-action server action
- verify middleware passes userId into context
- stub the session and assert a serverError without it
- test the useAction hook with renderHook
- catch a bind-argument validation error in a test
Example prompts for the agent
- Write Vitest tests for the
createUseraction in@/app/actions, covering success and validation errors - Test the auth middleware: build the client and mock
getSession - Add a
renderHooktest foruseActionthat checks its states andreset
How to install safe-action-testing
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-testing -a claude-code2Manually: put the files in place
~/.claude/skills/safe-action-testing/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/safe-action-testing/
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-testing -a codex2Manually: put the files in place
.agents/skills/safe-action-testing/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-testing -a cursor2Manually: put the files in place
.cursor/skills/safe-action-testing/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install next-safe-action/skills safe-action-testing2Manually: put the files in place
.github/skills/safe-action-testing/SKILL.md1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-testing -a gemini-cli2Platform CLI
gemini skills install https://github.com/next-safe-action/skills --path skills/safe-action-testingManually: put the files in place
.devin/skills/safe-action-testing/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-testing -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about safe-action-testing
How do I install safe-action-testing in Claude Code?
Run npx skills add next-safe-action/skills --skill safe-action-testing -a claude-code. The skill lands at ~/.claude/skills/safe-action-testing/SKILL.md.
What does safe-action-testing do?
It hands your agent Vitest templates for next-safe-action actions and hooks: direct action calls, middleware, renderHook, validation errors and server errors.
How are bind arguments tested?
Bind-argument validation failures are thrown as ActionBindArgsValidationError, so tests assert with rejects.toThrow() rather than checking validationErrors on the result.