testing-server-actions

Generate isolated unit tests for React 19 server actions with Vitest mocking patterns.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill testing-server-actions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-server-actions
Source: https://github.com/djankies/claude-configs/tree/main/react-19/concerns/testing/skills/testing-server-actions
Command: npx skills add https://github.com/djankies/claude-configs --skill testing-server-actions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Server Actions contain critical server-side logic, requiring thorough testing in isolation to ensure correctness, data integrity, and security. This Skill provides patterns for effectively testing these functions.

Core Features & Use Cases

  • Basic Server Action Test: Write tests for simple Server Actions, verifying input validation and expected outcomes.
  • Mocking Database Calls: Learn to mock database interactions to isolate Server Action logic during testing.
  • Testing with Authentication: Verify that Server Actions correctly enforce authentication and authorization rules.
  • Use Case: Write unit tests for the deleteProduct Server Action, ensuring it validates user permissions, correctly mocks database deletion, and handles unauthorized access attempts gracefully.

Quick Start

Write a test for the submitFeedback Server Action in src/actions.js to verify it handles invalid input and successfully saves valid data.

Frequently Asked Questions about testing-server-actions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Server Actions in React 19?

Testing Server Actions in React 19 involves writing isolated unit tests using Vitest to verify server-side logic, input validation, and expected outcomes. Mock database calls and external dependencies to test the action logic in isolation without hitting real services.

How do I mock database calls in Server Action tests?

Use Vitest mocking patterns to replace database interactions with test doubles. Mock the database module or client before each test, define expected return values, and verify the action calls the database correctly with the right parameters.

Can I test Server Actions with form submission and FormData?

Yes. Create FormData objects in tests, pass them to Server Actions, and assert that the action validates inputs correctly and handles both valid and invalid submissions. Test templates show how to construct FormData and verify success or error results.

How do I verify authentication and authorization in Server Action tests?

Mock authentication context or user session state, then test that Server Actions enforce permission rules. Write separate test cases for authorized and unauthorized access attempts to ensure the action rejects requests appropriately.

What should I test in a Server Action unit test?

Test input validation, authorization checks, database operations, and error handling. Verify that valid inputs produce expected outcomes, invalid inputs are rejected, unauthorized users cannot execute the action, and errors are handled gracefully.

Why isolate Server Action logic during testing?

Isolated testing ensures Server Actions enforce data integrity and security rules correctly without relying on external systems. This catches bugs in critical server-side logic early and prevents unauthorized access or data corruption in production.