testing

Implement Vitest mock patterns and TDD planning rules for JavaScript/TypeScript tests.

143|52|Updated May 15, 2026
One-click install
npx skills add https://github.com/gotgenes/pi-packages --skill testing-gotgenes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/gotgenes/pi-packages/tree/main/.pi/skills/testing
Command: npx skills add https://github.com/gotgenes/pi-packages --skill testing-gotgenes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides guidance on Vitest mock patterns (vi.mock, vi.hoisted, vi.fn resets), TDD planning rules, and general test strategy to help developers write reliable tests with predictable behavior.

Core Features & Use Cases

  • Vitest mock patterns and best practices for stable tests, including hoisting and mock lifecycle management.
  • Typing mock functions in TypeScript to preserve mock APIs and test ergonomics.
  • Test organization and planning guidance to structure scalable suites and guardrail decisions.

Quick Start

Apply Vitest mock patterns and TDD planning rules when writing tests.

Frequently Asked Questions about testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use vi.mock and vi.hoisted correctly in Vitest?

Vitest mock patterns require vi.hoisted to manage hoisting behavior when using vi.mock, ensuring mocks are initialized before module imports. This approach provides predictable mock lifecycle management and stable test execution.

Why does my vi.mock implementation fail to override module exports in Vitest?

Vitest mock hoisting behavior often causes vi.mock failures when mock factories are not properly scoped. Implementing vi.hoisted ensures mock definitions resolve before module imports, preventing reference errors and unstable test patterns.

How do I type mock functions in TypeScript with Vitest?

Type mock functions in TypeScript using vi.fn to preserve mock APIs and test ergonomics. Proper typing ensures deterministic test patterns and robust test design while maintaining full access to Vitest mock assertion methods.

What is the best way to organize Vitest test suites for scalable TDD?

TDD planning rules guide test organization by structuring scalable suites with clear guardrail decisions. Applying these patterns ensures deterministic test behavior and robust test design across complex JavaScript and TypeScript projects.

When should I reset mock functions between Vitest tests?

Reset vi.fn mocks between tests to maintain deterministic test patterns and prevent state leakage. Managing the mock lifecycle properly ensures predictable behavior and robust test design across your Vitest suite.

Does this Vitest testing guidance apply to TypeScript projects?

Yes, this guidance applies to developers writing or debugging tests in JavaScript and TypeScript projects using Vitest, covering clear mock typing, deterministic test patterns, and robust test design edge-case considerations.