front-vitest
Skill18 starsChanged 2 months agoApache-2.0View on GitHub
Depth for Vitest tests of front-* React 19 SPAs when DOM, RTL, TanStack Query hooks, or TanStack Router route-tree tests are needed. USE WHEN: adding jsdom or testing-library, writing tsx render or renderHook tests, testing createMemoryHistory plus RouterProvider, Suspense UI, or React 19 act fixtures. DO NOT USE WHEN: Node-only services or queryOptions unit tests - follow the front-react path rule instead - or Workers pool tests.
- Reads credentials
In this repository60 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .agents/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- hooks/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- hooks/CLAUDE.mdCLAUDE.md
- .cursor/rules/backend/hono-gateway.mdcCursor rule
- .cursor/rules/backend/ports.mdcCursor rule
- .cursor/rules/backend/service-bindings.mdcCursor rule
- .cursor/rules/backend/workers-cache.mdcCursor rule
- .cursor/rules/backend/workers-config.mdcCursor rule
- .cursor/rules/contracts/contracts.mdcCursor rule
- .cursor/rules/core/agent-instructions.mdcCursor rule
- .cursor/rules/core/boundaries.mdcCursor rule
- .cursor/rules/core/guardrails.mdcCursor rule
- .cursor/rules/core/turborepo.mdcCursor rule
- .cursor/rules/core/worktrees.mdcCursor rule
- .cursor/rules/frontend/react.mdcCursor rule
- .cursor/rules/frontend/tailwind.mdcCursor rule
- .cursor/rules/frontend/tanstack-query.mdcCursor rule
- .cursor/rules/frontend/tanstack-router.mdcCursor rule
- .cursor/rules/frontend/vite-config.mdcCursor rule
- .cursor/rules/ops/cd.mdcCursor rule
- .cursor/rules/ops/changesets.mdcCursor rule
- .cursor/rules/ops/ci.mdcCursor rule
- .cursor/rules/ops/previews.mdcCursor rule
- .cursor/rules/ops/quality-report.mdcCursor rule
- .cursor/rules/ops/release.mdcCursor rule
- .cursor/rules/quality/code-style.mdcCursor rule
- .cursor/rules/quality/comments.mdcCursor rule
- .cursor/rules/quality/knip.mdcCursor rule
- .cursor/rules/quality/lint-config.mdcCursor rule
- .cursor/rules/quality/markdown-style.mdcCursor rule
- .cursor/rules/quality/naming.mdcCursor rule
- .cursor/rules/quality/simplicity.mdcCursor rule
- .cursor/rules/quality/testing.mdcCursor rule
- .cursor/rules/quality/typescript-config.mdcCursor rule
- .cursor/rules/tests/front-react.mdcCursor rule
- .cursor/rules/tests/hono-workers.mdcCursor rule
- cfSkill
- changesetSkill
- git-commitSkill
- honoSkill
- monorepo-agent-setupSkill
- playwright-cliSkill
- pnpmSkill
- react-doctorSkill
- reviewSkill
- review-stackSkill
- run-appSkill
- security-auditSkill
- skills-updateSkill
- tanstack-configSkill
- tanstack-devtoolsSkill
- tanstack-querySkill
- tanstack-routerSkill
- turborepoSkill
- ui-ux-design-best-practicesSkill
- vercel-react-best-practicesSkill
- workers-best-practicesSkill
- skills-updateSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 18
Keep package default environment node for existing Node suites.
- Distinctive: line 30
Prefer await act with an async callback.
- Distinctive: line 33
use with a promise needs a stable, cached promise under Suspense - never use fetch created during render.
- Distinctive: line 40
Use renderHook from @testing-library/react - not @testing-library/react-hooks.
- Very specific: line 61
Import committed routeTree from #/routeTree.gen.
- Distinctive: line 82
Search validation: drive via initialEntries query strings …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Front-app Vitest depth
Hard constraints and Node-first defaults live in the path-scoped rule .claude/rules/tests/front-react.md / .cursor/rules/tests/front-react.mdc. Load this skill only when you need harnesses beyond that rule.
Prerequisites
Installed in front-app (catalog deps): happy-dom, @testing-library/react, @testing-library/jest-dom, @testing-library/user-event, @testing-library/dom. jsdom is NOT installed - add it via the catalog only if one suite needs a per-file jsdom fallback for a happy-dom spec gap. Vitest bundles no DOM. Do not invent a DOM suite under plain Node.
Environment and setup
Keep package default environment node for existing Node suites. A DOM suite opts in per file with the control comment // @vitest-environment happy-dom on line 1 (installed default; jsdom only as a per-file fallback, see Prerequisites).
Setup file apps/front-app/vitest.setup.ts (wired via setupFiles): sets globalThis.IS_REACT_ACT_ENVIRONMENT = true for every suite, then behind a typeof document !== "undefined" guard imports @testing-library/jest-dom/vitest and registers afterEach(cleanup) - Node suites skip the harness entirely - Vitest globals are off, so RTL auto-cleanup never registers, and isolate: false would leak DOM state across files without it. React act requires that flag; see https://react.dev/reference/react/act .
Vitest config for JSX
A separate vitest.config.ts ignores vite.config.ts unless you mergeConfig https://vitest.dev/config/ . front-app's vitest.config.ts already loads @vitejs/plugin-react, so JSX/tsx suites work as-is.
Do not blindly mergeConfig the full apps/front-app/vite.config.ts - it loads cloudflare, prod env asserts, Devtools. Add only needed plugins. Never cloudflareTest on front-*. If adding the TanStack Router Vite plugin under Vitest, place it before react. Use #/* imports - never invent @/. Prefer vi.stubEnv over .env.production. Coverage is not configured for front-app - do not invent thresholds.
React 19 in tests
- Prefer await act with an async callback. Sync act is discouraged and will be deprecated. Prefer RTL render / userEvent, which wrap act.
- ref is a normal prop - do not add forwardRef in new fixtures.
- StrictMode double-invokes render/effects/ref callbacks in development only. Vitest does not mount StrictMode unless the test tree does.
- use with a promise needs a stable, cached promise under Suspense - never use fetch created during render.
- useActionState is the React 19 name formerly useFormState in canaries.
TanStack Query hooks RTL
Fresh QueryClient per test, or clear between tests; avoid parallel share. Defaults: retry false, gcTime Infinity. Query-level retry still wins.
Use renderHook from @testing-library/react - not @testing-library/react-hooks. Wrap with QueryClientProvider. Await waitFor until isSuccess, then assert data.
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { renderHook, waitFor } from "@testing-library/react";
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, gcTime: Infinity } },
});
const wrapper = ({ children }: { children: React.ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
const { result } = renderHook(() => useCustomHook(), { wrapper });
await waitFor(() => expect(result.current.isSuccess).toBe(true));Suspense gap: Query testing guide does not prescribe a Vitest Suspense harness retrieved 2026-08-11. Prefer queryClient.query(opts) on queryOptions unless Suspense UI is the subject. If testing useSuspenseQuery, wrap with Suspense plus an error boundary. Do not combine suspense hooks with enabled or placeholderData.
TanStack Router file-based
Import committed routeTree from #/routeTree.gen. Never hand-edit; regenerate via pnpm --filter=front-app run routes:generate.
Canonical pattern matches Router package tests and apps/front-app/src/main.tsx: QueryClientProvider outside RouterProvider with no children. Always pass context.queryClient when loaders call queryClient.query.
import { routeTree } from "#/routeTree.gen";
import { createMemoryHistory, createRouter } from "@tanstack/react-router";
const history = createMemoryHistory({
initialEntries: ["/"],
});
const router = createRouter({
routeTree,
history,
context: { queryClient },
});Then render QueryClientProvider wrapping RouterProvider alone. Await screen.findByText, then waitFor until router.state.status is idle. Call RTL cleanup in afterEach. Navigate with await act around router.navigate.
Search validation: drive via initialEntries query strings https://tanstack.com/router/latest/docs/framework/react/how-to/validate-search-params
Isolated logic may use a manual mini tree createRootRoute / createRoute without the generated tree - that does not replace codegen for app routes.
Doc caveat: some TanStack how-tos wrap RouterProvider with children and a dummy ui. This app mounts provider-only. Prefer provider-only for full route-tree tests.
Extra gotchas DOM / harness
| Symptom | Fix |
| window is not defined | Add // @vitest-environment happy-dom on line 1 of the test file |
| act environment warning | Setup IS_REACT_ACT_ENVIRONMENT or use RTL |
| JSX fails under Vitest | Add @vitejs/plugin-react to Vitest config; do not merge full app Vite config |
| Suspended UI missing | Suspense + error boundary, or test via queryClient.query |
| Flaky sync act | await act with async callback, or RTL |
| Loader stale after search | Fix loaderDeps in route; put search in initialEntries |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

