home / skills / greyhaven-ai / claude-code-config / react-tanstack-testing

This skill provides comprehensive TanStack testing patterns for React apps, including mocks, router validation, and query behavior with Vite and Vitest.

npx playbooks add skill greyhaven-ai/claude-code-config --skill react-tanstack-testing

Review the files below or copy the command above to add this skill to your agents.

Files (11)
SKILL.md
1.4 KB
---
name: grey-haven-react-tanstack-testing
description: "Specialized testing for React applications using TanStack ecosystem (Query, Router, Table, Form) with Vite and Vitest. Use when testing React + TanStack apps, mocking server state, testing router, or validating query behavior. Triggers: 'TanStack testing', 'React Query testing', 'test TanStack', 'mock query', 'router test'."
# v2.0.43: Skills to auto-load for React TanStack testing
skills:
  - grey-haven-tanstack-patterns
  - grey-haven-testing-strategy
  - grey-haven-code-style
# v2.0.74: Tools for testing work
allowed-tools:
  - Read
  - Write
  - MultiEdit
  - Bash
  - Grep
  - Glob
  - TodoWrite
---

# React TanStack Testing Skill

Specialized testing for React applications using TanStack ecosystem (Query, Router, Table, Form) with Vite and Vitest.

## Description

Comprehensive testing patterns for modern React with TanStack libraries including server state management, routing, and data handling.

## What's Included

- **Examples**: TanStack Query tests, Router tests, Form validation
- **Reference**: Testing patterns, mocking strategies
- **Templates**: Test suites for TanStack components
- **Checklists**: React testing best practices

## Use When

- Testing React + TanStack Query applications
- Testing complex routing with TanStack Router
- Validating server state management

## Related Agents

- `react-tanstack-tester`
- `test-generator`

**Skill Version**: 1.0

Overview

This skill provides specialized testing patterns and ready-made templates for React applications using the TanStack ecosystem (Query, Router, Table, Form) with Vite and Vitest. It centralizes examples, mocking strategies, and checklists so teams can write reliable, fast tests for server state, routing, and UI behaviors. The goal is to reduce boilerplate and improve confidence when changing data-fetching or navigation logic.

How this skill works

The skill supplies test suites, reusable helpers, and mocking patterns that integrate TanStack Query, TanStack Router, Table, and Form with Vitest and Vite. It includes examples for mocking server state, controlling query lifecycles, simulating router navigation, and asserting table and form behaviors. Helpers wrap common setup/teardown, test providers, and network stubbing so tests stay focused on behavior rather than plumbing.

When to use it

  • Testing React components that rely on TanStack Query for server state
  • Validating navigation and route transitions with TanStack Router
  • Unit and integration tests for forms and tables using TanStack Form/Table
  • When you need deterministic tests for query caching, invalidation, and retries
  • When migrating to Vite/Vitest and needing TanStack-compatible test patterns

Best practices

  • Wrap components with provided test providers to mirror app context (QueryClient, Router)
  • Mock network responses and time-based behaviors to keep tests deterministic
  • Test side effects like cache updates and invalidations, not just rendered output
  • Prefer small, focused tests: isolate query behavior or router transitions per test
  • Use the supplied templates to standardize setup and reduce duplicated fixtures

Example use cases

  • Write a Vitest suite that asserts data refetch and cache invalidation after a mutation
  • Simulate route changes and verify guarded routes, params, and nested layouts with TanStack Router
  • Test a table component’s sorting and pagination by stubbing data responses
  • Validate form validation flows and submission side effects with mocked mutations
  • Create a snapshot of query loading, success, and error states for a component using QueryClient

FAQ

Do I need Vite and Vitest to use this skill?

The examples target Vite and Vitest for fast native ESM testing, but the patterns and helpers can be adapted to other runners with compatible APIs.

How do I mock server state reliably across tests?

Use the included network stubbing helpers and reset QueryClient between tests. Stub responses per test and control timers for retries and backoff to keep behavior deterministic.