← Back to list

vitest
by mcclowes
OAS Markdown Grammar is a human-first domain-specific language for API specification
⭐ 1🍴 0📅 Jan 12, 2026
SKILL.md
name: vitest
prettier-ignore
description: Use when writing or configuring Vitest tests - assertions, mocking, coverage, and workspace-aware testing for TypeScript projects
Vitest Testing Framework
Quick Start
import { describe, it, expect, vi, beforeEach } from 'vitest';
describe('Calculator', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('adds numbers correctly', () => {
expect(add(2, 3)).toBe(5);
});
it('handles async operations', async () => {
const result = await fetchData();
expect(result).toMatchObject({ id: 1 });
});
it('mocks dependencies', () => {
const mockFn = vi.fn().mockReturnValue(42);
expect(mockFn()).toBe(42);
expect(mockFn).toHaveBeenCalledOnce();
});
});
Core Assertions
| Assertion | Purpose |
|---|---|
toBe(value) | Strict equality (===) |
toEqual(value) | Deep equality |
toMatchObject(obj) | Partial object match |
toContain(item) | Array/string contains |
toThrow(error?) | Function throws |
toMatchSnapshot() | Snapshot testing |
toHaveBeenCalledWith() | Mock call verification |
Mocking
// Mock module
vi.mock('./api', () => ({ fetchUser: vi.fn() }));
// Spy on method
const spy = vi.spyOn(object, 'method');
// Mock implementation
mockFn.mockImplementation((x) => x * 2);
mockFn.mockResolvedValue({ data: [] });
mockFn.mockRejectedValue(new Error('fail'));
Configuration (vitest.config.ts)
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['**/*.test.ts'],
coverage: { provider: 'v8', reporter: ['text', 'html'] }
}
});
CLI Commands
vitest- Watch modevitest run- Single runvitest run --coverage- With coveragevitest --workspace- Monorepo mode
Score
Total Score
65/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
✓タグ
1つ以上のタグが設定されている
+5
Reviews
💬
Reviews coming soon
