Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
oakoss avatar

Vitest Testing

  • 164 installs
  • 14 repo stars
  • Updated March 2, 2026
  • oakoss/agent-skills

Author Vitest unit and integration tests with mocks, coverage thresholds, and monorepo-aware config before release.

About

Instructs agents to set up Vitest for TypeScript and JavaScript projects, including test structure, mocking strategies, coverage configuration, and monorepo package boundaries so regressions are caught before deploy.

  • Vitest config
  • Mocks and stubs
  • Coverage gates
  • Monorepo tests
  • Fast unit runs

Vitest Testing by the numbers

  • 164 all-time installs (skills.sh)
  • +8 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Ranked #858 of 2,153 Testing & QA skills by installs in the Skillselion catalog
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/oakoss/agent-skills --skill vitest-testing

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs164
repo stars14
Last updatedMarch 2, 2026
Repositoryoakoss/agent-skills

What it does

Author Vitest unit and integration tests with mocks, coverage thresholds, and monorepo-aware config before release.

Files

SKILL.mdMarkdownGitHub ↗

Vitest Testing

Overview

Vitest is a Vite-native unit testing framework that shares the same configuration and plugin ecosystem. Built for speed with native ESM support, hot module replacement for tests, and parallel execution.

When to use: Unit tests, component tests, integration tests, hook tests, in-source tests. Testing React components with React Testing Library. Testing TanStack Query/Router/Form patterns.

When NOT to use: End-to-end testing (use Playwright), visual regression testing (use Percy/Chromatic), load testing (use k6).

Quick Reference

PatternAPIKey Points
Test structuredescribe('suite', () => {})Organize related tests
Single testtest('behavior', () => {}) or it()Both are aliases
Parameterized teststest.each([...])('name', (arg) => {})Run same test with different inputs
Concurrent teststest.concurrent('name', async () => {})Run tests in parallel
Skip testtest.skip('name', () => {}) or skipIf(cond)Conditionally skip tests
Only testtest.only('name', () => {})Run specific test for debugging
Assertionsexpect(value).toBe(expected)Compare primitive values
Deep equalityexpect(obj).toEqual(expected)Compare objects/arrays
Async assertionsawait expect(promise).resolves.toBe(value)Test promise resolution
Before each testbeforeEach(() => {})Setup before each test
After each testafterEach(() => {})Cleanup after each test
Mock functionvi.fn()Create spy function
Mock modulevi.mock('./module')Replace entire module
Spy on methodvi.spyOn(obj, 'method')Track calls to existing method
Clear mocksvi.clearAllMocks()Clear call history
Fake timersvi.useFakeTimers()Control setTimeout/setInterval
Render componentrender(<Component />)Mount React component for testing
Query by rolescreen.getByRole('button')Find elements by accessibility role
User interactionawait user.click(element)Simulate user events
Wait for changeawait waitFor(() => expect(...))Wait for async changes
Find async elementawait screen.findByText('text')Query + wait combined
Render hookrenderHook(() => useHook())Test custom hooks
Update hook propsrerender(newProps)Re-render hook with new props
Snapshotexpect(value).toMatchSnapshot()Compare against saved snapshot
Inline snapshotexpect(value).toMatchInlineSnapshot()Snapshot stored in test file
CLI run oncevitest runSingle run, no watch
Run changed testsvitest --changedTests affected by git changes
Filter by namevitest -t "pattern"Grep test names
Soft assertionsexpect.soft(value).toBe(x)Continue on failure, collect all
Poll assertionsawait expect.poll(() => val).toBe(x)Retry until passing
Test fixturesconst test = base.extend<F>({...})Reusable setup via test.extend
Hoisted mocksvi.hoisted(() => ({ fn: vi.fn() }))Variables for vi.mock factory
Shard testsvitest --shard 1/3Split across CI workers
Tagstest('name', { tags: ['slow'] }, ...)Filter with --tags-filter
Stub globalsvi.stubGlobal('fetch', vi.fn())Replace global objects cleanly

Common Mistakes

MistakeCorrect Pattern
Using getBy for async contentUse findBy or waitFor for async
Testing implementation detailsTest behavior and public API
Using getByTestId as first choicePrefer getByRole, getByLabelText, getByText
Missing userEvent.setup()Always call const user = userEvent.setup() first
Shared state between testsUse beforeEach to reset or create fresh instances
Not cleaning up mocksUse vi.clearAllMocks() in afterEach
Mocking too muchOnly mock external dependencies and APIs
Not disabling retries in testsSet retry: false for TanStack Query tests
Immediate assertions on asyncUse await waitFor() or findBy queries
Creating QueryClient in renderCreate once in wrapper or use useState
Testing library codeTrust the library, test your usage
Not awaiting user eventsAll user.* methods return promises
Using act manuallyuserEvent and Testing Library handle this
Inline select without memoizationExtract to stable function for TanStack Query
Variables in vi.mock factoryUse vi.hoisted() to declare mock variables
Single expect for multiple checksUse expect.soft() to collect all failures
setTimeout in tests for async waitsUse expect.poll() or vi.waitFor()
Manual beforeEach for reusable setupUse test.extend fixtures for composable setup

Delegation

  • Test discovery: For finding untested code paths, use Explore agent
  • Coverage analysis: For full coverage review, use Task agent
  • E2E testing: If playwright skill is available, delegate E2E testing to it
  • Code review: After writing tests, delegate to code-reviewer agent

References

  • Test fundamentals: structure, assertions, lifecycle hooks
  • Mocking: vi.fn, vi.mock, vi.spyOn, module mocking
  • Component testing: React Testing Library, queries, user-event
  • Hook testing: renderHook, async hooks, TanStack patterns
  • Test setup: jest-dom matchers, cleanup, custom render, MSW, polyfills
  • Configuration: vitest.config.ts, workspace, coverage, reporters
  • Advanced patterns: snapshots, concurrent tests, in-source, type testing
  • CLI and filtering: commands, watch mode, tags, sharding
  • Fixtures and context: test.extend, scoping, auto fixtures, injection

Related skills

Testing & QAtestingfrontendbackend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.