Vitest

From jaem1n207/synchronize-tab-scrolling · View interactive version

Vitest is an AI agent skill from the GitHub repository jaem1n207/synchronize-tab-scrolling. Assists with unit and integration testing using Vitest, a Vite-native test runner. Use when writing tests, configuring mocks, setting up coverage, or migrating from Jest. Trigger words: vitest, unit testing, test runner, vi.fn, vi.mock, test coverage, jest replacement.

How to use this skill

Skill file

Vitest

Overview

Vitest is a Vite-native test runner that provides a Jest-compatible API with native ESM support, instant watch mode via Vite's HMR, and shared Vite configuration for aliases, plugins, and transforms. It serves as a drop-in Jest replacement with significantly faster startup and execution.

Instructions

Examples

Example 1: Test a service with API mocking

User request: "Write Vitest tests for a user service that calls an external API"

Actions:

  1. Mock the HTTP module with vi.mock() to intercept API calls
  2. Write tests for success, error, and edge cases using describe and it
  3. Assert responses with toEqual() and error handling with toThrow()
  4. Use beforeEach with vi.clearAllMocks() for test isolation

Output: Isolated unit tests for the user service with mocked external dependencies.

Example 2: Migrate from Jest to Vitest

User request: "Switch our test suite from Jest to Vitest"

Actions:

  1. Install vitest and add test config to vite.config.ts
  2. Replace jest.fn() with vi.fn() and jest.mock() with vi.mock()
  3. Update package.json scripts to use vitest and vitest --coverage
  4. Remove ts-jest, babel-jest, and Jest config files

Output: A Vitest-powered test suite with the same tests running faster with native ESM support.

Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.