Topics
- Frontend
- Testing
- vitest
- react-testing-library
- rtl
- dify
- components
- hooks
- unit-tests
- integration-tests
What it does
Generates Vitest and React Testing Library tests for Dify frontend components, hooks, and utilities following the project's conventions. Tests use the AAA pattern, semantic queries, and an incremental one-file-at-a-time workflow; mocks external dependencies like API services and next/navigation while importing real project components.
Generated from the current SKILL.md.
Frequently asked
Does this skill cover E2E testing or only unit/integration tests?
This skill covers unit and integration tests for frontend components, hooks, and utilities using Vitest and React Testing Library. E2E tests (Cucumber + Playwright) are out of scope; use the E2E testing skill for those.
What should I mock and what should I import as real?
Mock only external dependencies like API services (`@/service/*`), `next/navigation`, and complex context providers. Import and use real project components, base components from `@/app/components/base/*`, and dify-ui primitives directly in tests.
How should I organize test files in the Dify project?
Test files must live in a sibling `__tests__/` directory at the same level as the source. For example, `foo/index.tsx` maps to `foo/__tests__/index.spec.tsx`, and `foo/bar.ts` maps to `foo/__tests__/bar.spec.ts`.
Should I write all tests at once or incrementally?
Always use an incremental approach. Analyze and list files, order by complexity (simple to complex), then write and run tests one file at a time, verifying each passes before proceeding to the next.
How do I test components that use `useQueryState` from nuqs?
Use `NuqsTestingAdapter` from the shared helpers in `web/test/nuqs-testing.tsx` and assert URL synchronization via `onUrlUpdate`. Ensure custom parsers maintain bijective `parse` and `serialize` functions.
Generated from the current SKILL.md. These answers refresh after source changes.