vitest

Apply Vitest best practices for async handling, mocking, and test isolation.

4|Updated Jan 8, 2026
One-click install
npx skills add https://github.com/allthingslinux/portal --skill vitest-allthingslinux
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/allthingslinux/portal/tree/main/.cursor/skills/vitest
Command: npx skills add https://github.com/allthingslinux/portal --skill vitest-allthingslinux

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Vitest testing patterns guide to improve reliability, performance, and correctness of tests across async code, mocks, and setup.

Core Features & Use Cases

  • Async patterns best practices for awaiting assertions, using waitFor, fake timers, and proper error handling.
  • Test setup & isolation guidelines: avoiding shared state, proper cleanup, mocking strategies, and module resets.
  • Performance and environment optimization tips, snapshot hygiene, and environment mocks for consistent results.
  • Use case examples: migrating from Jest, improving CI reliability, writing scalable tests.

Quick Start

Follow Vitest best practices when starting or refactoring tests. Focus on writing async assertions with await, using waitFor for UI updates, enabling fake timers for time-dependent code, and ensuring mocks are reset after each test.

Frequently Asked Questions about vitest

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

FAQPage Schema
How do I fix flaky Vitest tests caused by async assertions?

Fix flaky Vitest tests by properly awaiting async assertions, using waitFor for UI updates, and enabling fake timers for time-dependent code to ensure reliable execution.

What is the best way to isolate tests and reset mocks in Vitest?

Isolate Vitest tests by avoiding shared state, performing proper cleanup, and ensuring mocks are reset after each test with module resets to maintain robust test suites.

How do I migrate from Jest to Vitest for my JavaScript testing setup?

Migrate from Jest to Vitest by applying structured patterns for async handling, test isolation, and mocking to produce fast, reliable, and maintainable JavaScript test suites.

Why are my Vitest tests slow in CI and how can I optimize performance?

Optimize slow Vitest tests in CI by applying performance and environment optimization tips, maintaining snapshot hygiene, and using environment mocks for consistent results.

When should I use fake timers in Vitest testing patterns?

Use fake timers in Vitest when testing time-dependent code to control temporal execution, preventing timing-related flakiness and ensuring reliable, synchronous test outcomes.