Agent skill

Vitest Best Practices

by PageAI-Pro in PageAI-Pro/ralph-loop

Comprehensive vitest testing patterns covering test structure, AAA pattern, parameterized tests, assertions, mocking, test doubles, error handling, async testing, and performance optimization.

MITAuto-check passedTesting & QA

Install Vitest Best Practices

skills CLI
$ npx skills add PageAI-Pro/ralph-loop --skill vitest-best-practices -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install PageAI-Pro/ralph-loop vitest-best-practices --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/PageAI-Pro/ralph-loop.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agent/skills/vitest-best-practices .claude/skills/vitest-best-practices && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
vitest-best-practices
GitHub stars
315
Token cost
~1.2k tokens
SKILL.md length
426 words
Files
12 (incl. references)
Skills in repo
4
Repo updated
First seen
Licence
MIT

At a glance

Comprehensive vitest testing patterns covering test structure, AAA pattern, parameterized tests, assertions, mocking, test doubles, error handling, async testing, and performance optimization.

  • Works in 3 steps: Start with the Overview (AGENTS.md) → Load Specific Rules as Needed → Apply the Pattern
  • Refactoring vitest tests
  • SKILL.md covers When to Apply This Skill, Do NOT Use This Skill When, What This Skill Covers and How to Use, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Vitest Best Practices is an agent skill from PageAI-Pro/ralph-loop. Comprehensive vitest testing patterns covering test structure, AAA pattern, parameterized tests, assertions, mocking, test doubles, error handling, async testing, and performance optimization. Use when writing, reviewing, or refactoring vitest tests, or when user mentions vitest, testing, TDD, test coverage, mocking, assertions, or test files (.test.ts, .spec.ts).

Its SKILL.md is about 1.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 12 other files, including reference files (for example `AGENTS.md`, `references/aaa-pattern.md` and `references/assertions.md`). Compatibility notes: Requires vitest testing framework

It sits in Testing & QA, covering Unit testing. It works with Vitest. The repository describes itself as: A long-running AI agent loop. Ralph automates software development tasks by iteratively working through a task list until completion. The licence is MIT.

When your agent uses it

  • Refactoring vitest tests
  • User mentions vitest
  • Test files (.test.ts

Example prompts

  • “/vitest-best-practices”

Requirements

  • Compatibility (from SKILL.md): Requires vitest testing framework

Workflow steps

3 steps, taken from the step headings in SKILL.md.

  1. Start with the Overview (AGENTS.md)
  2. Load Specific Rules as Needed
  3. Apply the Pattern

What it can do on your machine

Read from SKILL.md and the folder at commit eba65eb. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Requires vitest testing framework

    From compatibility in the SKILL.md frontmatter.

Context cost

Vitest Best Practices loads about 1.2k tokens when it runs, and up to ~26k if it reads all its reference files. Until then it costs about 98 tokens; SKILL.md has 426 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~98
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~26k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from PageAI-Pro/ralph-loop at commit eba65eb, republished under its MIT licence (© PageAI-Pro). 426 words, ~1,220 tokens.

Download SKILL.mdSave it as .claude/skills/vitest-best-practices/SKILL.md (or your agent's skills folder). This skill also uses 11 other files; get the full folder from GitHub.
name
vitest-best-practices
description
Comprehensive vitest testing patterns covering test structure, AAA pattern, parameterized tests, assertions, mocking, test doubles, error handling, async testing, and performance optimization. Use when writing, reviewing, or refactoring vitest tests, or when user mentions vitest, testing, TDD, test coverage, mocking, assertions, or test files (*.test.ts, *.spec.ts).
compatibility
Requires vitest testing framework

Vitest Best Practices

When to Apply This Skill

Use this skill when you encounter any of these scenarios:

File Patterns
  • Working with *.test.ts, *.spec.ts, or similar test files
  • Creating new test files for TypeScript/JavaScript modules
  • Reviewing existing vitest test suites
User Intent Keywords
  • User mentions: vitest, testing, TDD, BDD, unit tests, integration tests
  • User asks to: write tests, add test coverage, fix failing tests, refactor tests
  • User discusses: mocking, stubbing, assertions, test performance, test organization
Code Context
  • Files importing from vitest (describe, it, expect, vi)
  • Test setup/teardown code (beforeEach, afterEach, beforeAll, afterAll)
  • Mock/spy implementations using vi.mock(), vi.spyOn(), vi.fn()
  • Assertion chains (expect(...).toEqual(), .toBe(), .toThrow(), etc.)
Common Tasks
  • Writing new test cases for existing functionality
  • Refactoring tests for better clarity or performance
  • Debugging flaky or failing tests
  • Improving test coverage or maintainability
  • Reviewing test code for best practices compliance

Do NOT Use This Skill When

  • Writing end-to-end tests with Playwright/Cypress (different scope)
  • The task is purely about implementation code, not tests

What This Skill Covers

This skill provides comprehensive guidance on:

  1. Test Organization: File placement, naming conventions, grouping strategies
  2. AAA Pattern: Arrange, Act, Assert structure for clarity
  3. Parameterized Tests: Using it.each() for testing variations
  4. Error Handling: Testing exceptions, edge cases, and fault injection
  5. Assertions: Choosing strict assertions (toEqual, toStrictEqual, toThrow)
  6. Test Doubles: Fakes, stubs, mocks, spies - when to use each
  7. Async Testing: Promises, async/await, timers, and concurrent tests
  8. Performance: Fast tests, avoiding expensive operations, cleanup patterns
  9. Vitest-Specific Features: Coverage, watch mode, benchmarking, type testing, setup files
  10. Snapshot Testing: When and how to use snapshots effectively
Show full SKILL.md (163 more words)Show less

How to Use

This skill uses a progressive disclosure structure to minimize context usage:

1. Start with the Overview (AGENTS.md)

Read AGENTS.md for a concise overview of all rules with one-line summaries.

2. Load Specific Rules as Needed

When you identify a relevant optimization, load the corresponding reference file for detailed implementation guidance:

Core Patterns:

Advanced Topics:

3. Apply the Pattern

Each reference file contains:

  • ❌ Incorrect examples showing the anti-pattern
  • ✅ Correct examples showing the optimal implementation
  • Explanations of why the pattern matters

Quick Example

This skill helps you transform unclear tests into clear, maintainable ones:

Before (unclear):

ts
test('product test', () => {
  const p = new ProductService().add({name: 'Widget'});
  expect(p.status).toBe('pendingApproval');
});

After (optimized with this skill):

ts
describe('ProductService', () => {
  describe('Add new product', () => {
    it('should have status "pending approval" when no price is specified', () => {
      // Arrange
      const productService = new ProductService();

      // Act
      const newProduct = productService.add({name: 'Widget'});

      // Assert
      expect(newProduct.status).toEqual('pendingApproval');
    });
  });
});

Key Principles

  • Clarity over cleverness: Tests should be instantly understandable
  • Flat structure: Avoid deep nesting in describe blocks
  • One assertion per concept: Focus tests on single behaviors
  • Strict assertions: Prefer toEqual over toBe, toStrictEqual when needed
  • Minimal mocking: Use real implementations when practical
  • Fast execution: Keep tests quick through efficient setup/teardown

© PageAI-Pro, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 11 other files (references) in .agent/skills/vitest-best-practices of PageAI-Pro/ralph-loop.

  • SKILL.md
  • AGENTS.md
  • references/aaa-pattern.md
  • references/assertions.md
  • references/async-testing.md
  • references/error-handling.md
  • references/organization.md
  • references/parameterized-tests.md
  • references/performance.md
  • references/snapshot-testing.md
  • references/test-doubles.md
  • references/vitest-features.md

Open the folder on GitHubat commit eba65eb

Compare with similar skills

Vitest Best Practices next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Vitest Best Practices compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Vitest Best Practices this skillPageAI-Pro/ralph-loop315—~1.2kAutomated safety check: PassMIT
Test Writing WorkflowiOfficeAI/AionUi33k1 repos~1.2kAutomated safety check: PassApache-2.0
Vitestsupabase/supabase111k12 repos~1.1kAutomated safety check: PassApache-2.0
Test GuardamElnagdy/guard-skills1.3k2 repos~2.1kAutomated safety check: PassMIT
Adding LLM MCP ToolsTriliumNext/Trilium38k—~2.5kAutomated safety check: PassAGPL-3.0
Concept Page Test Writerleonardomso/33-js-concepts67k—~5.5kAutomated safety check: PassMIT

Similar skills

  • Test Writing Workflow

    iOfficeAI/AionUi

    Sets the test-writing workflow for the repository: risk-first scenario lists, behavior-focused Vitest tests, a full run before each commit and a coverage target.

    33k GitHub starsUsed in 1 repo~1.2k tokens
    Testing & QAAuto-check passed
  • Vitest

    supabase/supabase

    Official

    Vitest API and config reference (Jest-compatible) — mocking with vi., spies, fake timers, coverage configuration, fixtures, snapshots, and test filtering.

    111k GitHub starsUsed in 12 repos~1.1k tokens
    Testing & QAAuto-check passed
  • Test Guard

    amElnagdy/guard-skills

    Reviews newly written or edited tests against nine rules that cut test bloat, such as mock-heavy checks and near-duplicate cases, before they are committed.

    1.3k GitHub starsUsed in 2 repos~2.1k tokens
    Testing & QAAuto-check passed
  • Adding LLM MCP Tools

    TriliumNext/Trilium

    A skill your agent uses when adding, changing, or reviewing an LLM/MCP tool in Trilium (the defineTools definitions under packages/trilium-core/src/services/llm/tools/ —…

    38k GitHub stars~2.5k tokensUpdated yesterday
    Testing & QAAuto-check passed
  • Concept Page Test Writer

    leonardomso/33-js-concepts

    Generates Vitest tests for every runnable code example on a JavaScript concept documentation page, following a four-phase extraction and conversion process.

    67k GitHub stars~5.5k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • Archestra Dev Testing

    archestra-ai/archestra

    A skill your agent uses for test selection and quality across backend, frontend, and e2e; load its backend reference for Vitest projects, mocking, DB fixtures, and performance.

    4.4k GitHub stars~3.2k tokensUpdated yesterday
    Testing & QAAuto-check passed

More from PageAI-Pro/ralph-loop

  • Component Refactoring

    PageAI-Pro/ralph-loop

    Refactor high-complexity React components in frontend. An agent skill from PageAI-Pro/ralph-loop.

    315 GitHub stars~1.8k tokensUpdated 1 mo ago
    Auto-check passed
  • E2E Tester

    PageAI-Pro/ralph-loop

    Playwright E2E testing patterns. An agent skill from PageAI-Pro/ralph-loop.

    315 GitHub stars~4.3k tokensUpdated 1 mo ago
    Auto-check: notes
  • Prd Creator

    PageAI-Pro/ralph-loop

    Guides creation of comprehensive Product Requirement Documents (PRDs) for software projects through structured questioning and validation, then generates implementation task lists in JSON format.

    315 GitHub stars~1.6k tokensUpdated 1 mo ago
    Auto-check: notes

Works with

Categories

Questions about Vitest Best Practices

What does Vitest Best Practices do?

Comprehensive vitest testing patterns covering test structure, AAA pattern, parameterized tests, assertions, mocking, test doubles, error handling, async testing, and performance optimization. Vitest Best Practices is an agent skill from PageAI-Pro/ralph-loop. Comprehensive vitest testing patterns covering test structure, AAA pattern, parameterized tests, assertions, mocking, test doubles, error handling, async testing, and performance optimization.

When should I use Vitest Best Practices?

Vitest Best Practices fits situations like: refactoring vitest tests; user mentions vitest; test files (.test.ts.

How do I install Vitest Best Practices in Claude Code?

Run `npx skills add PageAI-Pro/ralph-loop --skill vitest-best-practices -a claude-code`. Or copy the skill folder (.agent/skills/vitest-best-practices in PageAI-Pro/ralph-loop) into .claude/skills/vitest-best-practices in your project. Claude Code loads it when a task matches its description.

How do I install Vitest Best Practices in Codex?

Run `npx skills add PageAI-Pro/ralph-loop --skill vitest-best-practices -a codex`. Or copy the skill folder (.agent/skills/vitest-best-practices in PageAI-Pro/ralph-loop) into .agents/skills/vitest-best-practices in your project. Codex loads it when a task matches its description.

Can I use Vitest Best Practices in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add PageAI-Pro/ralph-loop --skill vitest-best-practices -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/vitest-best-practices, .gemini/skills/vitest-best-practices, .github/skills/vitest-best-practices and .opencode/skills/vitest-best-practices in your project.

What does Vitest Best Practices need to run?

SKILL.md names no scripts, command-line tools or credentials: Vitest Best Practices is instructions for the agent only. Compatibility (from SKILL.md): Requires vitest testing framework.

Does Vitest Best Practices access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Vitest Best Practices safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Vitest Best Practices use?

Vitest Best Practices is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Vitest Best Practices use?

About 1.2k tokens (SKILL.md is roughly 4.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 25k tokens, read only when the agent opens those files.

What are the alternatives to Vitest Best Practices?

Skills that share tags, products or a category with Vitest Best Practices: Test Writing Workflow (iOfficeAI/AionUi, 33k stars), Vitest (supabase/supabase, 111k stars), Test Guard (amElnagdy/guard-skills, 1.3k stars) and Adding LLM MCP Tools (TriliumNext/Trilium, 38k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Vitest Best Practices?

PageAI-Pro (a GitHub organization) maintains it in PageAI-Pro/ralph-loop, which has 315 GitHub stars. The repository holds 4 skills in this directory. The repository was last updated on August 31, 2026.

Source: PageAI-Pro/ralph-loop on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.