No slash command · from react-plugin
Provides patterns for testing React SPAs: RTL + Vitest/Jest for components/hooks, msw for network mocks, Playwright/Cypress for e2e. Covers query priority, user events, async assertions, and mocking.
Ships in react-plugin. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
| Layer | Framework |
|---|---|
| Component, hook, plain TS unit | Vitest (preferred for new) or Jest |
| End-to-end | Playwright or Cypress |
Match what's installed. Vitest is the modern default for Vite projects; Jest is common in CRA / older setups.
vitest.config.ts:
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig({
plugins: [react()],
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./vitest.setup.ts'],
css: true,
coverage: {
reporter: ['text', 'html'],
exclude: ['**/*.config.*', '**/*.test.*', 'src/main.tsx'],
},
},
resolve: {
alias: { '@': path.resolve(__dirname, './src') },
},
});
vitest.setup.ts:
import '@testing-library/jest-dom/vitest';
import { afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';
afterEach(() => cleanup());
Install: pnpm add -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/user-event @testing-library/jest-dom.
jest.config.ts:
import type { Config } from 'jest';
const config: Config = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEach: ['<rootDir>/jest.setup.ts'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'\\.(css|scss|less)$': 'identity-obj-proxy',
},
};
export default config;
jest.setup.ts:
import '@testing-library/jest-dom';
// src/features/users/UserCard.test.tsx
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { UserCard } from './UserCard';
describe('UserCard', () => {
it('renders user name and email', () => {
render(<UserCard user={{ id: '1', name: 'Alice', email: '[email protected]' }} />);
expect(screen.getByRole('heading', { name: 'Alice' })).toBeInTheDocument();
expect(screen.getByText('[email protected]')).toBeInTheDocument();
});
it('calls onDelete when delete button clicked', async () => {
const onDelete = vi.fn();
const user = userEvent.setup();
render(<UserCard user={{ id: '1', name: 'Alice', email: '[email protected]' }} onDelete={onDelete} />);
await user.click(screen.getByRole('button', { name: /delete/i }));
expect(onDelete).toHaveBeenCalledWith('1');
});
});
getByRole(role, { name }) — accessible name. Mirrors how screen readers see the page.getByLabelText — for form inputs.getByPlaceholderText — fallback for inputs without label.getByText — for non-interactive text.getByDisplayValue — for inputs with current value.getByAltText — for images.getByTitle — for elements with title attribute.getByTestId — last resort, when nothing else works.getBy* throws if not found. queryBy* returns null. findBy* is async (returns promise that retries).
expect(screen.queryByText('Loading...')).not.toBeInTheDocument(); // assert absence
expect(await screen.findByText('Loaded')).toBeInTheDocument(); // wait for async
import userEvent from '@testing-library/user-event';
const user = userEvent.setup();
await user.click(button);
await user.type(input, 'hello');
await user.selectOptions(select, 'option-value');
await user.upload(input, file);
await user.tab(); // keyboard navigation
await user.keyboard('{Enter}');
fireEvent is lower-level and skips realistic event sequences (mousedown→mouseup→click). Stick to user-event.
// src/hooks/useDebounce.test.ts
import { describe, it, expect, vi } from 'vitest';
import { renderHook, act } from '@testing-library/react';
import { useDebounce } from './useDebounce';
describe('useDebounce', () => {
it('returns the latest value after delay', async () => {
vi.useFakeTimers();
const { result, rerender } = renderHook(({ value }) => useDebounce(value, 300), {
initialProps: { value: 'a' },
});
expect(result.current).toBe('a');
rerender({ value: 'b' });
expect(result.current).toBe('a'); // not yet debounced
act(() => {
vi.advanceTimersByTime(300);
});
expect(result.current).toBe('b');
vi.useRealTimers();
});
});
// vitest.setup.ts
import { setupServer } from 'msw/node';
import { http, HttpResponse } from 'msw';
import { afterAll, afterEach, beforeAll } from 'vitest';
const server = setupServer(
http.get('/api/users', () => HttpResponse.json([{ id: '1', name: 'Alice' }])),
http.post('/api/users', async ({ request }) => {
const body = await request.json();
return HttpResponse.json({ id: '2', ...body }, { status: 201 });
}),
);
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
export { server };
Per-test override:
import { http, HttpResponse } from 'msw';
import { server } from '../vitest.setup';
it('shows error on 500', async () => {
server.use(http.get('/api/users', () => HttpResponse.json({ error: 'oops' }, { status: 500 })));
render(<UsersPage />);
expect(await screen.findByText(/error/i)).toBeInTheDocument();
});
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { render } from '@testing-library/react';
function renderWithQuery(ui: React.ReactElement) {
const qc = new QueryClient({
defaultOptions: { queries: { retry: false } }, // don't retry in tests
});
return render(<QueryClientProvider client={qc}>{ui}</QueryClientProvider>);
}
it('shows users from API', async () => {
renderWithQuery(<UsersList />);
expect(await screen.findByText('Alice')).toBeInTheDocument();
});
import { MemoryRouter, Routes, Route } from 'react-router-dom';
it('navigates to user detail', async () => {
const user = userEvent.setup();
render(
<MemoryRouter initialEntries={['/users']}>
<Routes>
<Route path="/users" element={<UsersList />} />
<Route path="/users/:id" element={<UserDetail />} />
</Routes>
</MemoryRouter>
);
await user.click(screen.getByRole('link', { name: 'Alice' }));
expect(await screen.findByText('User Detail: 1')).toBeInTheDocument();
});
For data routers (with loader etc.), use createMemoryRouter and RouterProvider.
it('shows validation errors and submits valid data', async () => {
const onSubmit = vi.fn();
const user = userEvent.setup();
render(<LoginForm onSubmit={onSubmit} />);
// Submit empty
await user.click(screen.getByRole('button', { name: /log in/i }));
expect(await screen.findByText(/invalid email/i)).toBeInTheDocument();
expect(onSubmit).not.toHaveBeenCalled();
// Fill correctly
await user.type(screen.getByLabelText(/email/i), '[email protected]');
await user.type(screen.getByLabelText(/password/i), 'longenough');
await user.click(screen.getByRole('button', { name: /log in/i }));
await waitFor(() => {
expect(onSubmit).toHaveBeenCalledWith({ email: '[email protected]', password: 'longenough' });
});
});
playwright.config.ts:
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './e2e',
webServer: {
command: 'npm run dev',
url: 'http://localhost:5173',
reuseExistingServer: !process.env.CI,
},
use: { baseURL: 'http://localhost:5173', trace: 'on-first-retry' },
projects: [
{ name: 'chromium', use: { browserName: 'chromium' } },
],
});
// e2e/login.spec.ts
import { test, expect } from '@playwright/test';
test('user can log in', async ({ page }) => {
await page.goto('/login');
await page.getByLabel(/email/i).fill('[email protected]');
await page.getByLabel(/password/i).fill('longenough');
await page.getByRole('button', { name: /log in/i }).click();
await expect(page).toHaveURL('/dashboard');
await expect(page.getByRole('heading', { name: /welcome/i })).toBeVisible();
});
// cypress/e2e/login.cy.ts
describe('login', () => {
it('user can log in', () => {
cy.visit('/login');
cy.get('[name=email]').type('[email protected]');
cy.get('[name=password]').type('longenough');
cy.contains('button', 'Log in').click();
cy.url().should('include', '/dashboard');
});
});
Cypress feels more "live" (interactive runner) but each test is browser-resident, slower at scale than Playwright.
Target ≥80% on:
Skip / lower bar:
main.tsx.Configure exclusions:
// vitest.config.ts
test: {
coverage: {
exclude: [
'src/main.tsx',
'src/App.tsx',
'**/*.config.*',
'**/types.ts',
'**/*.stories.tsx',
],
},
}
The qa-engineer agent has a hard 3-attempt cap on fixing failing tests. Mark genuinely flaky tests it.skip(...) with a comment after attempt #3, and report in the QA summary.
getByTestId everywhere instead of accessible queries.fireEvent for interactions when userEvent would be more realistic.fetch directly when msw exists in the project.act() warnings — they signal real issues with async state updates.webServer config or seed data.setTimeout waits in tests — use findBy* (which retries) or waitFor.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
React, Vitest, Jest, Playwright, Cypress
react-testing, rtl, vitest, jest, msw, playwright, cypress
5 skills in this plugin
/react-conventionsReact component structure, hooks rules, file naming, project layout, composition patterns, performance idioms, and effects discipline. Apply when implementing or modifying React SPA code.
Use this skill to:
- Structure a new component or feature folder.
- Apply hooks correctly (rules, naming, dependency arrays).
- Compose components via children, render props, or compound patterns.
- Write effects only when needed (and avoid common misuses).
- Pick performance escape hatches (memo, useMemo, useCallback) when justified.
Do NOT use this skill for:
- State management lib choice (see react-state-management).
- Routing primitives (see react-routing).
- Form patterns (see react-forms).
- Testing (see react-testing).
/react-formsForm patterns for React: react-hook-form (most common), Formik (legacy/stable), TanStack Form (newer). Validation via zod / yup / valibot. Controlled vs uncontrolled inputs, field arrays, multi-step wizards.
Use this skill to:
- Wire react-hook-form with a validation schema.
- Pick between controlled and uncontrolled patterns.
- Build multi-step forms with state preservation.
- Handle async validation (e.g., username availability).
- Integrate forms with TanStack Query mutations.
Do NOT use this skill for:
- General state management (see react-state-management).
- Routing (see react-routing).
- Component conventions (see react-conventions).
- Testing forms (see react-testing).
/react-routingRouting libraries for React SPAs: React Router v6/v7 (most common), TanStack Router (typed, modern), wouter (minimal). Detect what's installed and apply matching patterns. Lazy loading, navigation guards, typed params.
Use this skill to:
- Configure routes (declarative or file-based).
- Use navigation hooks (useNavigate, useParams, useSearchParams).
- Lazy-load routes for code splitting.
- Implement protected routes / auth guards.
- Type-safe params via Zod or framework's built-ins.
Do NOT use this skill for:
- General React conventions (see react-conventions).
- State management (see react-state-management).
- Form handling (see react-forms).
- Next.js routing (different model — see nextjs-plugin).
/react-state-managementState management decision tree for React SPAs: useState/useReducer, Context API, Zustand, Jotai, Redux Toolkit, TanStack Query, SWR. Detect what's installed and apply matching patterns.
Use this skill to:
- Pick the right state tool for the data shape (local / shared UI / server / form).
- Use Context correctly (and know when to switch to Zustand/Jotai).
- Implement a Zustand or Jotai store.
- Set up TanStack Query for server state with caching, pagination, mutations.
- Avoid common mistakes (overusing Redux, prop drilling, forgetting query invalidation).
Do NOT use this skill for:
- General hook conventions (see react-conventions).
- Form state specifically (see react-forms).
- Routing state (see react-routing).
- Testing stores/queries (see react-testing).
npx claudepluginhub aratkruglik/claude-sdlc --plugin react-pluginOther plugins' skills for the same job