Vitest

From InugamiDev/ultrathink-oss · View interactive version

Vitest is an AI agent skill from the GitHub repository InugamiDev/ultrathink-oss. > Blazing fast unit testing powered by Vite — Jest-compatible API, native ESM, TypeScript.

How to use this skill

Skill file

Vitest

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

When to Use

Core Patterns

Configuration

// 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

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

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.