Skip to content
Back to skills

Vitest

ASecurity

> Blazing fast unit testing powered by Vite — Jest-compatible API, native ESM, TypeScript.

  • 2 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added October 26, 2026
testingtypescriptreactvuetestingapi

Works with

  • api

Security analysis

A100/100

Scanned October 26, 2026

npx -y skills add nhan03bit/ultrathink --skill vitest --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Vitest?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Vitest
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nhan03bit-vitest/badge)](https://www.skillsdirectory.com/skills/nhan03bit-vitest)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Vitest

> Blazing fast unit testing powered by Vite — Jest-compatible API, native ESM, TypeScript.

## When to Use
- Unit and integration testing for Vite/React/Vue/Svelte projects
- Replacing Jest with faster, ESM-native alternative
- Component testing with happy-dom or jsdom
- In-source testing (tests alongside implementation)

## Core Patterns

### Configuration
```typescript
// vitest.config.ts
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  test: {
    globals: true,           // No need for import { test, expect }
    environment: "happy-dom", // or "jsdom" for browser APIs
    setupFiles: ["./test/setup.ts"],
    coverage: {
      provider: "v8",
      reporter: ["text", "html"],
    },
    include: ["src/**/*.{test,spec}.{ts,tsx}"],
  },
});
```

### Testing
```typescript
import { describe, it, expect, vi, beforeEach } from "vitest";

describe("UserService", () => {
  beforeEach(() => { vi.clearAllMocks(); });

  it("creates user", async () => {
    const mockDb = vi.fn().mockResolvedValue({ id: "1", name: "Inu" });
    const user = await createUser(mockDb, { name: "Inu" });
    expect(user).toMatchObject({ id: "1", name: "Inu" });
    expect(mockDb).toHaveBeenCalledOnce();
  });

  it("throws on invalid input", () => {
    expect(() => validateName("")).toThrow("Name required");
  });
});
```

### Key Features
- **vi.fn()**: Mock functions (same API as jest.fn())
- **vi.mock()**: Module mocking with auto-mock support
- **vi.spyOn()**: Spy on object methods
- **Snapshots**: `expect(result).toMatchSnapshot()`
- **In-source**: `if (import.meta.vitest)` blocks stripped from production
- **Watch mode**: `vitest` (default), `vitest run` for CI
- **Workspace**: `vitest.workspace.ts` for monorepo testing
- **Type testing**: `expectTypeOf<string>().toMatchTypeOf<string>()`
- **Browser mode**: `vitest --browser` for real browser testing

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.