vitest-4

Automate Vitest testing pattern adoption in TypeScript and JavaScript projects.

Updated Jun 22, 2024
One-click install
npx skills add https://github.com/KilloconQ/dotfiles --skill vitest-4
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest-4
Source: https://github.com/KilloconQ/dotfiles/tree/main/opencode/.config/opencode/skills/vitest-4
Command: npx skills add https://github.com/KilloconQ/dotfiles --skill vitest-4

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Vitest 4 testing patterns and best practices streamline test writing, organization, and reliability by providing consistent patterns for asserts, mocks, spies, and module mocking.

Core Features & Use Cases

  • Establishes recommended test structure using AAA pattern and isolated tests.
  • Demonstrates clear assertion strategies (toBe, toEqual, toStrictEqual, etc.) and appropriate use of mocks, spies, and vi.mock.
  • Covers async testing, fake timers, parameterized tests, and snapshot/testing organization.
  • Provides guidance on building robust tests for vitest in TypeScript projects with examples.

Quick Start

Write a Vitest test file following describe/it/test blocks with asserts; for example, import { describe, it, test, expect } from "vitest"; run tests via vitest to verify behavior.

Frequently Asked Questions about vitest-4

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

FAQPage Schema
Does Vitest support parameterized tests and snapshot testing?

Vitest supports parameterized tests for running multiple data scenarios and snapshot testing for tracking UI or output changes. These features, combined with structured test organization, help verify behavior comprehensively across varied inputs and maintain reliable frontend test suites.

How do I structure maintainable Vitest unit tests in TypeScript?

Maintainable Vitest unit tests use the AAA pattern within isolated describe, it, and test blocks to separate setup, execution, and assertion phases clearly. This structure ensures reliable mocks and spies while keeping your TypeScript frontend or backend test suites organized.

What is the best way to mock modules in Vitest?

The best way to mock modules in Vitest is using vi.mock for module-level mocking and spies to track function calls. This approach ensures robust testing workflows by replacing dependencies and validating interactions without altering actual implementations.

When should I use toEqual vs toStrictEqual in Vitest assertions?

Use toEqual for deep equality checks ignoring undefined properties, and toStrictEqual for strict type and structure matching in Vitest assertions. Applying explicit matchers correctly prevents false positives and ensures your TypeScript objects match expected schemas exactly.

How do I test async workflows and manage fake timers with Vitest?

Testing async workflows with Vitest involves awaiting promises inside it blocks and utilizing fake timers to control time-dependent operations. Proper restoration of mocks and timers after each test maintains isolation and prevents cascading test failures.

Does Vitest support parameterized tests and snapshot testing?

Vitest supports parameterized tests for running multiple data scenarios and snapshot testing for tracking UI or output changes. These features, combined with structured test organization, help verify behavior comprehensively across varied inputs and maintain reliable frontend test suites.