What problem does it solve?
Testing next-safe-action server actions, middleware, and hooks is error-prone and time-consuming without structured patterns.
Core Features & Use Cases
- Testing Actions Directly: Call server actions directly in tests and assert results, server errors, and validation errors.
- Testing Actions with Bind Args: Validate bound actions with pre-supplied arguments to ensure correct outputs.
- Testing Middleware: Verify middleware chains (authentication, error propagation) in isolation and in combination with actions.
- Testing Hooks: Use React Testing Library's renderHook to validate hook behavior and integration with actions.
- Testing Validation Errors: Utilize utilities to flatten and format validation errors for reliable assertions.
- Mocking Framework Errors: Mock Next.js navigation to safely test redirects and not-found scenarios.
- Test File Organization: Follow the project convention for organizing tests under tests and action/hook/middleware folders.
Quick Start
Run the Vitest suite for next-safe-action tests to validate actions, middleware, and hooks.