vitest_runner
Modern JavaScript/TypeScript testing with Vitest including mocking and coverage.
от vuralserhat86★ 43 звезды на GitHub
Установить vitest_runner в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Vitest
Description
Modern JavaScript/TypeScript testing with Vitest including mocking and coverage.
When to Use
- Testing JavaScript/TypeScript
- React component testing
- Unit and integration tests
Core Patterns
Basic Tests
import { describe, it, expect } from 'vitest';
describe('math', () => {
it('should add numbers', () => {
expect(1 + 1).toBe(2);
});
it('should throw on invalid input', () => {
expect(() => divide(1, 0)).toThrow('Division by zero');
});
});
Mocking
import { vi, describe, it, expect } from 'vitest';
// Mock module
vi.mock('./api', () => ({
fetchUser: vi.fn().mockResolvedValue({ id: 1 })
}));
// Mock function
const callback = vi.fn();
callback('arg');
expect(callback).toHaveBeenCalledWith('arg');
Async Tests
it('should fetch data', async () => {
const data = await fetchData();
expect(data).toEqual({ id: 1 });
});
it('should reject on error', async () => {
await expect(fetchData()).rejects.toThrow('Error');
});
React Testing
import { render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
it('should handle click', async () => {
const onClick = vi.fn();
render(<Button onClick={onClick}>Click</Button>);
await userEvent.click(screen.getByRole('button'));
expect(onClick).toHaveBeenCalled();
});
🔄 Workflow
Kaynak: Vitest Official Documentation & Vite + Testing Best Practices
Aşama 1: Environment & Setup
- Vite Integration:
vitest.config.tsdosyasının Vite ayarlarıyla senkronize olduğunu doğrula. - Environment Choice: Web projeleri için
jsdomveyahappy-dom, backend içinnodeenvironment'ı seç. - Global Mocks: Sık kullanılan harici servisler (API, LocalStorage) için
setup.tsiçinde global mock'ları tanımla.
Aşama 2: Unit & Component Testing
- Isolation Layer: Bağımlılıkları
vi.mock()ile izole ederek sadece hedef üniteyi test et. - Assertion Strategy:
expectmetodlarını kullanarak beklenen sonuçları (be.truthy, toEqual, toBeCalled) doğrula. - Snapshot Testing: UI bileşenlerindeki (Component) beklenmedik arayüz değişikliklerini
toMatchSnapshot()ile yakala.
Aşama 3: Performance & Coverage
- Watch Mode: Geliştirme sürecinde testleri
watchmodunda tutarak anlık geri bildirim al. - Coverage Analysis:
v8veyaistanbulprovider kullanarak test kapsamını raporla. - Dependency Cleanup:
vi.clearAllMocks()ile testler arası veri kirliliğini (Pollution) önle.
Kontrol Noktaları
| Aşama | Doğrulama |
|---|---|
| 1 | Test dosyaları *.test.ts veya *.spec.ts formatında mı? |
| 2 | Asenkron kodlar (async/await) doğru handle ediliyor mu? |
| 3 | Karmaşık nesne karşılaştırmalarında toBe (referans) yerine toEqual (değer) mi kullanıldı? |
Vitest Runner v1.5 - With Workflow
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл vitest_runner?
Modern JavaScript/TypeScript testing with Vitest including mocking and coverage.
Как установить скилл vitest_runner?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл vitest_runner запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…