testing-vitest
Skill1 starsChanged 26 days agoMITView on GitHub
Write and run tests with Vitest 5, Testing Library and jest-dom in this project — page smoke tests, component behaviour tests, hook tests, service mocks and script tests. Use when adding tests, fixing failing tests, raising coverage or deciding what to test.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- mhihasan/agentic-sdlctheir own version, first seen Oct 15, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- mhihasan/agentic-sdlc★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository18 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/rtv-architecture.mdcCursor rule
- .cursor/rules/rtv-code-style.mdcCursor rule
- .cursor/rules/rtv-design-system.mdcCursor rule
- .cursor/rules/rtv-git-workflow.mdcCursor rule
- .cursor/rules/rtv-testing.mdcCursor rule
- accessibility-auditSkill
- ci-cd-dockerSkill
- clean-code-reviewSkill
- dependency-upgradeSkill
- deployment-insightsSkill
- project-architectureSkill
- react-componentSkill
- scaffold-featureSkill
- tailwind-design-systemSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
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 65
Prefer testing through a component.
- Very specific: line 78
Read the assertion and the rendered DOM (screen.debug()).
- Distinctive: line 79
Check the accessible name/role you query against the markup.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Testing with Vitest
Commands
npm test # watch mode
npm run test:run # single run (CI)
npm run test:run -- __tests__/pages # a folder or file
npm run coverage # v8 coverage → coverage/index.htmlConfig lives in vite.config.ts (test block): happy-dom environment at http://localhost:3000/, globals on, vitest.setup.ts loads @testing-library/jest-dom/vitest. Tests are discovered in __tests__/** and src/**/*.test.tsx.
Page smoke test (generated for every template)
import { render, screen } from '@testing-library/react'
import { describe, expect, test } from 'vitest'
import Dashboard from '@pages/Dashboard'
describe('<Dashboard />', () => {
test('renders the page heading', () => {
render(<Dashboard />)
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Overview')
})
})Behaviour test
import { fireEvent, render, screen } from '@testing-library/react'
test('shows validation errors on empty submit', () => {
render(<SignInForm onSubmit={vi.fn()} />)
fireEvent.click(screen.getByRole('button', { name: /sign in/i }))
expect(screen.getByText('Email address is required.')).toBeInTheDocument()
})Query priority: getByRole (with name) → getByLabelText → getByText → getByTestId (last resort). Use findBy* for async UI and queryBy* to assert absence.
Mocking at the boundary
vi.mock('@services/customers', () => ({
listCustomers: vi.fn().mockResolvedValue([{ id: 1, name: 'Ada' }]),
}))Or stub fetch: vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify(data)))). Reset in afterEach(() => vi.restoreAllMocks()). Fake timers: vi.useFakeTimers() + vi.advanceTimersByTime(ms).
Hooks
Prefer testing through a component. For isolated logic use renderHook from @testing-library/react and act for updates.
Scripts (bin/, scripts/)
Plain ESM tests in __tests__/scripts/*.test.mjs import the libraries directly (import { checkImports } from '../../scripts/lib/imports.mjs'). Use fs.mkdtempSync for file-system scenarios and never touch the repository itself.
What to test (and not)
- ✅ Rendering of every page, validation and error states, conditional UI, hooks' observable behaviour, services' request shaping and error mapping, architecture/catalogue integrity.
- ❌ Tailwind class names, third-party internals (Headless UI focus trapping), snapshots of large trees, implementation details (state variable names).
Failing test triage
- Read the assertion and the rendered DOM (
screen.debug()). - Check the accessible name/role you query against the markup.
- Async?
await screen.findBy…orawait waitFor(...). - Environment? URL is
http://localhost:3000/;window.matchMediaexists in happy-dom but returnsmatches: false.
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.

