agentleFS
tuanductrantuanductran/tester-skills/skills/unit-testing-vitest/SKILL.md

unit-testing-vitest

Skill0 starsChanged 4 months agoMITView on GitHub

Unit testing guidelines for Vitest (and Jest-compatible) JavaScript/TypeScript projects. Use this skill whenever writing, reviewing, or refactoring unit tests, adding vi mocks, configuring coverage, or debugging flaky/async test failures. Triggers on tasks involving *.test.ts, *.spec.ts files, vi.fn/vi.mock/vi.spyOn usage, Vitest config, or any request to "write tests", "add unit tests", "mock this", or "improve test coverage".

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
  1. Very specific:

    Read rules/_sections.md for full category descriptions.

    line 70
  2. Distinctive:

    When reviewing existing tests, check them against the HIGH-impact rules first (structure, assertions, mocking, async), then MEDIUM.

    line 72
  3. Very specific:

    When writing new tests, default to the AAA pattern, prefer vi.spyOn over full vi.mock when only one function needs stubbing, and always …

    line 73

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Unit Testing (Vitest)

Guidelines for writing reliable, fast, and maintainable unit tests with Vitest in JS/TS projects. Contains 13 rules across 6 categories, prioritized by impact.

When to Apply

Reference these guidelines when:

  • Writing new unit tests for functions, classes, or components
  • Adding or reviewing vi.fn() / vi.mock() / vi.spyOn() usage
  • Configuring Vitest coverage thresholds or CI gates
  • Debugging a test that's flaky, hangs, or silently passes
  • Refactoring code and needing tests that won't break on implementation changes

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Test Structure & NamingHIGHstructure-
2AssertionsHIGHassert-
3Mocking & Test DoublesHIGHmock-
4Async & TimersHIGHasync-
5Coverage & CIMEDIUMcoverage-
6Performance & IsolationMEDIUMperf-

Quick Reference

1. Test Structure & Naming (HIGH)

  • structure-aaa-pattern - Arrange-Act-Assert in every test
  • structure-descriptive-names - Name tests after behavior, not method
  • structure-one-behavior-per-test - One assertion focus per test

2. Assertions (HIGH)

  • assert-specific-matchers - Use the most specific matcher available
  • assert-behavior-not-implementation - Assert output, not internals

3. Mocking & Test Doubles (HIGH)

  • mock-vi-fn-spyon - Choose vi.fn/vi.spyOn/vi.mock deliberately
  • mock-reset-restore - Reset/restore mocks between tests
  • mock-avoid-mocking-what-you-own - Don't mock code you can test directly

4. Async & Timers (HIGH)

  • async-await-promises - Always await async assertions
  • async-fake-timers - Use vi.useFakeTimers() instead of real delays

5. Coverage & CI (MEDIUM)

  • coverage-ci-thresholds - Gate CI on explicit coverage thresholds
  • coverage-dont-chase-100 - Don't chase 100% on low-risk code

6. Performance & Isolation (MEDIUM)

  • perf-test-isolation - Keep tests isolated for safe parallel runs

How to Use This Skill

  1. Read rules/_sections.md for full category descriptions.
  2. For a specific task, open the relevant rule file(s) under rules/ — each has an incorrect/correct code example.
  3. When reviewing existing tests, check them against the HIGH-impact rules first (structure, assertions, mocking, async), then MEDIUM.
  4. When writing new tests, default to the AAA pattern, prefer vi.spyOn over full vi.mock when only one function needs stubbing, and always await async assertions.

See rules/_template.md for the format used by every rule file.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.