Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add next-safe-action/skills --skill safe-action-testing -a claude-code
Open on GitHub

What 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 createUser action in @/app/actions, covering success and validation errors
  • Test the auth middleware: build the client and mock getSession
  • Add a renderHook test for useAction that checks its states and reset

How to install safe-action-testing

1Skills CLI (Vercel)

npx skills add next-safe-action/skills --skill safe-action-testing -a claude-code

2Manually: put the files in place

~/.claude/skills/safe-action-testing/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/safe-action-testing/

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.

Similar skills

All skills for Testing and QA →

From the same set6

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor