FormingSkillclaude-codepublished fresh until

Vitest skill: how do I get my agent to write correct tests and mocks?

Summary Anthony Fu's vitest skill (MIT, in antfu/skills, generated from the Vitest 5.0.1 docs) gives the agent a short index and 19 reference files for config, mocking, fixtures, coverage and the vi utilities, to help it avoid Jest-style tests that fail on Vitest. Do first: Check package.json for the project’s Vitest version.

Not for browser e2e tests or over-mocked tests; see agent-e2e-tests-selector-collisions-leftover-data, agent-tests-mock-everything-real-db-rollback-factories

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
ASkill · v1.0.0+wwfix.1vitest skill (Anthony Fu)
How you use itYou ask for it
What it can doinstalls software · writes files · network · runs shell
What's inside
ASkill · v1.0.0+wwfix.1vitest skill (Anthony Fu)
How you use it
You ask for it
What it can do
installs software · writes files · network · runs shell
What's inside

What this thread does

The problem

Agents write Vitest tests from memory of Jest: jest.fn() instead of vi.fn(), mocks declared after the import they should replace, fake timers never restored, config that ignores the project's Vite setup. The tests look fine and fail in odd ways, or pass without testing anything.

What the package is

Anthony Fu publishes a Vitest skill in antfu/skills (MIT, locked to commit feb0f3a for this entry). The SKILL.md says it is generated from the Vitest docs and targets Vitest 5.0.1 (generated 2026-09-25). It is a short index plus 19 reference files (the GitHub listing at that commit), about 102 KB in total: config, CLI, test and expect APIs, hooks, mocking, snapshots, coverage, test context and fixtures, concurrency, filtering, tags, reporters, benchmarking, vi utilities, environments, type testing and projects.

What I read: the index links references the agent can load as needed (for example features-mocking.md for vi.mock and advanced-vi.md for vi.hoisted), so a task about mocking does not pull in the whole docs set. The skill is documentation, not a workflow: it does not tell the agent how to decide what to test.

How to describe it to the agent

A prompt worth trying (mine, untried): "Use the vitest skill. Write tests for src/lib/price.ts at its public functions only. Use vi.hoisted for any module mock factory, restore timers and mocks in afterEach, and run the tests with vitest run before you report."

Common mistakes

  • Treating the skill as a substitute for the version of Vitest in your repo: it describes 5.x; check package.json first.
  • Letting the agent mock your own modules everywhere; mock the boundary (network, clock), not the code under test.
  • Skipping the run: ask the agent to execute the suite and show the result.

Limits

I read the skill, not outputs from it. Prompt wording is mine and untried. It teaches the Vitest API, not what is worth testing; pair it with the thread on whether agent-written unit tests help.

Primary source

Primary source: antfu/skills vitest SKILL.md (Anthony Fu, commit feb0f3a, MIT licence file). Checked: generated from the Vitest repository, based on Vitest 5.0.1 (2026-09-25), an index linking reference files (config, CLI, test and expect APIs, hooks, mocking, snapshots, coverage and more); the commit lists 19 reference files totalling about 102 KB, not 20 and 105 KB as an earlier version of this thread said. Star count not verified.

Started from a post by @Anthony Fu, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vitest skill: how do I get my agent to write correct tests and mocks?
Summary: Anthony Fu's vitest skill (MIT, in antfu/skills, generated from the Vitest 5.0.1 docs) gives the agent a short index and 19 reference files for config, mocking, fixtures, coverage and the vi utilities, to help it avoid Jest-style tests that fail on Vitest. Do first: Check `package.json` for the project’s Vitest version.

## Options
- A · vitest skill (Anthony Fu) · early, no verdict yet · installs software · writes files · network · runs shell
Copy for agent
get the whatworks thread vitest-skill-agent-writes-correct-vitest-tests and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vitest-skill-agent-writes-correct-vitest-tests

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · vitest skill (Anthony Fu)

Vitest 5 documentation condensed for agents: an index SKILL.md and 19 reference files covering config, CLI, test and expect APIs, hooks, mocking, snapshots, coverage, fixtures, concurrency, filtering, tags, reporters, benchmarking, vi utilities, environments, type testing and projects.

Format
Skill
Source
github:antfu/skills#skills/vitest
Pinned
v1.0.0+wwfix.1 · feb0f3aba656
Content hash
feb0f3aba6566426
Audit
scan passed
Can do
installs software · writes files · network · runs shell
Works with
claude-code
Check
The installed skill's front matter names vitest.; The installed vi utilities reference documents vi.hoisted.; The installed mocking reference documents vi.mock.
Author
@antfu
Kudos
0
Are you @antfu? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package vitest-skill before installing

A · Files

Read from the package source at the pinned version. Shown as is; nothing here runs.

Loading files…

Ask your agent
show me the files of the whatworks package vitest-skill
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp