frontend-testing — frontend-testing AI agent skill frontend-testing, official, frontend-testing AI agent skill, ide skills, frontend-testing for Claude Code, Claude Code, Cursor, Windsurf

Verified
v1.0.0
GitHub

About this Skill

Perfect for Frontend Agents needing comprehensive React component testing with Vitest and React Testing Library. Generate Vitest + React Testing Library tests for Dify frontend components, hooks, and utilities. Triggers on testing, spec files, coverage, Vitest, RTL, unit tests, integration tests, or write/review test requests.

# Core Topics

langgenius langgenius
[135.1k]
[21035]
Updated: 3/31/2026

Agent Capability Analysis

The frontend-testing skill by langgenius is an open-source official AI agent skill for Claude Code and other IDE workflows, helping agents execute tasks with better context, repeatability, and domain-specific guidance. Optimized for frontend-testing AI agent skill, frontend-testing for Claude Code.

Ideal Agent Persona

Perfect for Frontend Agents needing comprehensive React component testing with Vitest and React Testing Library.

Core Value

Empowers agents to generate high-quality, comprehensive frontend tests for React components, hooks, and utilities using Vitest and React Testing Library, with features like test coverage improvement and mocking with vi.mock.

Capabilities Granted for frontend-testing

Generating Vitest tests for React components and hooks
Reviewing existing tests for completeness and coverage
Improving test coverage for frontend code using Vitest and RTL
Debugging frontend issues using Vitest's watch mode and test environment
Analyzing component complexity with pnpm analyze-component

! Prerequisites & Limits

  • Requires Vitest and React Testing Library setup
  • Limited to frontend testing, does not support backend/API or E2E tests
  • Requires TypeScript 5.x for type safety
Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

frontend-testing

Install frontend-testing, an AI agent skill for AI agent workflows and automation. Works with Claude Code, Cursor, and Windsurf with one-command setup.

SKILL.md
Readonly

Dify Frontend Testing Skill

This skill enables Claude to generate high-quality, comprehensive frontend tests for the Dify project following established conventions and best practices.

⚠️ Authoritative Source: This skill is derived from web/docs/test.md. Use Vitest mock/timer APIs (vi.*).

When to Apply This Skill

Apply this skill when the user:

  • Asks to write tests for a component, hook, or utility
  • Asks to review existing tests for completeness
  • Mentions Vitest, React Testing Library, RTL, or spec files
  • Requests test coverage improvement
  • Uses pnpm analyze-component output as context
  • Mentions testing, unit tests, or integration tests for frontend code
  • Wants to understand testing patterns in the Dify codebase

Do NOT apply when:

  • User is asking about backend/API tests (Python/pytest)
  • User is asking about E2E tests (Playwright/Cypress)
  • User is only asking conceptual questions without code context

Quick Reference

Tech Stack

ToolVersionPurpose
Vitest4.0.16Test runner
React Testing Library16.0Component testing
jsdom-Test environment
nock14.0HTTP mocking
TypeScript5.xType safety

Key Commands

bash
1# Run all tests 2pnpm test 3 4# Watch mode 5pnpm test:watch 6 7# Run specific file 8pnpm test path/to/file.spec.tsx 9 10# Generate coverage report 11pnpm test:coverage 12 13# Analyze component complexity 14pnpm analyze-component <path> 15 16# Review existing test 17pnpm analyze-component <path> --review

File Naming

  • Test files: ComponentName.spec.tsx inside a same-level __tests__/ directory
  • Placement rule: Component, hook, and utility tests must live in a sibling __tests__/ folder at the same level as the source under test. For example, foo/index.tsx maps to foo/__tests__/index.spec.tsx, and foo/bar.ts maps to foo/__tests__/bar.spec.ts.
  • Integration tests: web/__tests__/ directory

Test Structure Template

typescript
1import { render, screen, fireEvent, waitFor } from '@testing-library/react' 2import Component from './index' 3 4// ✅ Import real project components (DO NOT mock these) 5// import Loading from '@/app/components/base/loading' 6// import { ChildComponent } from './child-component' 7 8// ✅ Mock external dependencies only 9vi.mock('@/service/api') 10vi.mock('next/navigation', () => ({ 11 useRouter: () => ({ push: vi.fn() }), 12 usePathname: () => '/test', 13})) 14 15// ✅ Zustand stores: Use real stores (auto-mocked globally) 16// Set test state with: useAppStore.setState({ ... }) 17 18// Shared state for mocks (if needed) 19let mockSharedState = false 20 21describe('ComponentName', () => { 22 beforeEach(() => { 23 vi.clearAllMocks() // ✅ Reset mocks BEFORE each test 24 mockSharedState = false // ✅ Reset shared state 25 }) 26 27 // Rendering tests (REQUIRED) 28 describe('Rendering', () => { 29 it('should render without crashing', () => { 30 // Arrange 31 const props = { title: 'Test' } 32 33 // Act 34 render(<Component {...props} />) 35 36 // Assert 37 expect(screen.getByText('Test')).toBeInTheDocument() 38 }) 39 }) 40 41 // Props tests (REQUIRED) 42 describe('Props', () => { 43 it('should apply custom className', () => { 44 render(<Component className="custom" />) 45 expect(screen.getByRole('button')).toHaveClass('custom') 46 }) 47 }) 48 49 // User Interactions 50 describe('User Interactions', () => { 51 it('should handle click events', () => { 52 const handleClick = vi.fn() 53 render(<Component onClick={handleClick} />) 54 55 fireEvent.click(screen.getByRole('button')) 56 57 expect(handleClick).toHaveBeenCalledTimes(1) 58 }) 59 }) 60 61 // Edge Cases (REQUIRED) 62 describe('Edge Cases', () => { 63 it('should handle null data', () => { 64 render(<Component data={null} />) 65 expect(screen.getByText(/no data/i)).toBeInTheDocument() 66 }) 67 68 it('should handle empty array', () => { 69 render(<Component items={[]} />) 70 expect(screen.getByText(/empty/i)).toBeInTheDocument() 71 }) 72 }) 73})

Testing Workflow (CRITICAL)

⚠️ Incremental Approach Required

NEVER generate all test files at once. For complex components or multi-file directories:

  1. Analyze & Plan: List all files, order by complexity (simple → complex)
  2. Process ONE at a time: Write test → Run test → Fix if needed → Next
  3. Verify before proceeding: Do NOT continue to next file until current passes
For each file:
  ┌────────────────────────────────────────┐
  │ 1. Write test                          │
  │ 2. Run: pnpm test <file>.spec.tsx      │
  │ 3. PASS? → Mark complete, next file    │
  │    FAIL? → Fix first, then continue    │
  └────────────────────────────────────────┘

Complexity-Based Order

Process in this order for multi-file testing:

  1. 🟢 Utility functions (simplest)
  2. 🟢 Custom hooks
  3. 🟡 Simple components (presentational)
  4. 🟡 Medium components (state, effects)
  5. 🔴 Complex components (API, routing)
  6. 🔴 Integration tests (index files - last)

When to Refactor First

  • Complexity > 50: Break into smaller pieces before testing
  • 500+ lines: Consider splitting before testing
  • Many dependencies: Extract logic into hooks first

📖 See references/workflow.md for complete workflow details and todo list format.

Testing Strategy

Path-Level Testing (Directory Testing)

When assigned to test a directory/path, test ALL content within that path:

  • Test all components, hooks, utilities in the directory (not just index file)
  • Use incremental approach: one file at a time, verify each before proceeding
  • Goal: 100% coverage of ALL files in the directory

Integration Testing First

Prefer integration testing when writing tests for a directory:

  • Import real project components directly (including base components and siblings)
  • Only mock: API services (@/service/*), next/navigation, complex context providers
  • DO NOT mock base components (@/app/components/base/*)
  • DO NOT mock sibling/child components in the same directory

See Test Structure Template for correct import/mock patterns.

nuqs Query State Testing (Required for URL State Hooks)

When a component or hook uses useQueryState / useQueryStates:

  • ✅ Use NuqsTestingAdapter (prefer shared helpers in web/test/nuqs-testing.tsx)
  • ✅ Assert URL synchronization via onUrlUpdate (searchParams, options.history)
  • ✅ For custom parsers (createParser), keep parse and serialize bijective and add round-trip edge cases (%2F, %25, spaces, legacy encoded values)
  • ✅ Verify default-clearing behavior (default values should be removed from URL when applicable)
  • ⚠️ Only mock nuqs directly when URL behavior is explicitly out of scope for the test

Core Principles

1. AAA Pattern (Arrange-Act-Assert)

Every test should clearly separate:

  • Arrange: Setup test data and render component
  • Act: Perform user actions
  • Assert: Verify expected outcomes

2. Black-Box Testing

  • Test observable behavior, not implementation details
  • Use semantic queries (getByRole, getByLabelText)
  • Avoid testing internal state directly
  • Prefer pattern matching over hardcoded strings in assertions:
typescript
1// ❌ Avoid: hardcoded text assertions 2expect(screen.getByText('Loading...')).toBeInTheDocument() 3 4// ✅ Better: role-based queries 5expect(screen.getByRole('status')).toBeInTheDocument() 6 7// ✅ Better: pattern matching 8expect(screen.getByText(/loading/i)).toBeInTheDocument()

3. Single Behavior Per Test

Each test verifies ONE user-observable behavior:

typescript
1// ✅ Good: One behavior 2it('should disable button when loading', () => { 3 render(<Button loading />) 4 expect(screen.getByRole('button')).toBeDisabled() 5}) 6 7// ❌ Bad: Multiple behaviors 8it('should handle loading state', () => { 9 render(<Button loading />) 10 expect(screen.getByRole('button')).toBeDisabled() 11 expect(screen.getByText('Loading...')).toBeInTheDocument() 12 expect(screen.getByRole('button')).toHaveClass('loading') 13})

4. Semantic Naming

Use should <behavior> when <condition>:

typescript
1it('should show error message when validation fails') 2it('should call onSubmit when form is valid') 3it('should disable input when isReadOnly is true')

Required Test Scenarios

Always Required (All Components)

  1. Rendering: Component renders without crashing
  2. Props: Required props, optional props, default values
  3. Edge Cases: null, undefined, empty values, boundary conditions

Conditional (When Present)

FeatureTest Focus
useStateInitial state, transitions, cleanup
useEffectExecution, dependencies, cleanup
Event handlersAll onClick, onChange, onSubmit, keyboard
API callsLoading, success, error states
RoutingNavigation, params, query strings
useCallback/useMemoReferential equality
ContextProvider values, consumer behavior
FormsValidation, submission, error display

Coverage Goals (Per File)

For each test file generated, aim for:

  • 100% function coverage
  • 100% statement coverage
  • >95% branch coverage
  • >95% line coverage

Note: For multi-file directories, process one file at a time with full coverage each. See references/workflow.md.

Detailed Guides

For more detailed information, refer to:

  • references/workflow.md - Incremental testing workflow (MUST READ for multi-file testing)
  • references/mocking.md - Mock patterns, Zustand store testing, and best practices
  • references/async-testing.md - Async operations and API calls
  • references/domain-components.md - Workflow, Dataset, Configuration testing
  • references/common-patterns.md - Frequently used testing patterns
  • references/checklist.md - Test generation checklist and validation steps

Authoritative References

Primary Specification (MUST follow)

  • web/docs/test.md - The canonical testing specification. This skill is derived from this document.

Reference Examples in Codebase

  • web/utils/classnames.spec.ts - Utility function tests
  • web/app/components/base/button/index.spec.tsx - Component tests
  • web/__mocks__/provider-context.ts - Mock factory example

Project Configuration

  • web/vitest.config.ts - Vitest configuration
  • web/vitest.setup.ts - Test environment setup
  • web/scripts/analyze-component.js - Component analysis tool
  • Modules are not mocked automatically. Global mocks live in web/vitest.setup.ts (for example react-i18next, next/image); mock other modules like ky or mime locally in test files.

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is frontend-testing?

Perfect for Frontend Agents needing comprehensive React component testing with Vitest and React Testing Library. Generate Vitest + React Testing Library tests for Dify frontend components, hooks, and utilities. Triggers on testing, spec files, coverage, Vitest, RTL, unit tests, integration tests, or write/review test requests.

How do I install frontend-testing?

Run the command: npx killer-skills add langgenius/dify/frontend-testing. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for frontend-testing?

Key use cases include: Generating Vitest tests for React components and hooks, Reviewing existing tests for completeness and coverage, Improving test coverage for frontend code using Vitest and RTL, Debugging frontend issues using Vitest's watch mode and test environment, Analyzing component complexity with pnpm analyze-component.

Which IDEs are compatible with frontend-testing?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for frontend-testing?

Requires Vitest and React Testing Library setup. Limited to frontend testing, does not support backend/API or E2E tests. Requires TypeScript 5.x for type safety.

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add langgenius/dify/frontend-testing. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use frontend-testing immediately in the current project.

Related Skills

Looking for an alternative to frontend-testing or another official skill for your workflow? Explore these related open-source skills.

View All

flags

Logo of facebook
facebook

Use when you need to check feature flag states, compare channels, or debug why a feature behaves differently across release channels.

243.6k
0
Developer

extract-errors

Logo of facebook
facebook

Use when adding new error messages to React, or seeing unknown error code warnings.

243.6k
0
Developer

fix

Logo of facebook
facebook

Use when you have lint errors, formatting issues, or before committing code to ensure it passes CI.

243.6k
0
Developer

flow

Logo of facebook
facebook

Use when you need to run Flow type checking, or when seeing Flow type errors in React code.

243.6k
0
Developer