vitest-testing
БесплатноБез исполняемых скриптовНе проверенVitest v4 testing patterns, configuration, mocking, and verification gates. Use when writing unit or integration tests, configuring vitest.config, mocking…
от existential-birds★ 92 звезды на GitHubОб этом скилле
Vitest Best Practices
Quick Reference
import { describe, it, expect, beforeEach, vi } from 'vitest'
describe('feature name', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('should do something specific', () => {
expect(actual).toBe(expected)
})
it.todo('planned test')
it.skip('temporarily disabled')
it.only('run only this during dev')
})
Common Assertions
// Equality
expect(value).toBe(42) // Strict (===)
expect(obj).toEqual({ a: 1 }) // Deep equality
expect(obj).toStrictEqual({ a: 1 }) // Strict deep (checks types & undefined keys)
// Numbers & Strings/Arrays
expect(0.1 + 0.2).toBeCloseTo(0.3)
expect(str).toMatch(/pattern/)
expect(array).toContain(item)
expect(array).toHaveLength(3)
// Objects
expect(obj).toHaveProperty('nested.key', 'value')
expect(obj).toMatchObject({ subset: 'of properties' })
// Exceptions
expect(() => fn()).toThrow('error message')
expect(() => fn()).toThrow(/pattern/)
Async Testing
// Async/await (preferred)
it('fetches data', async () => {
const data = await fetchData()
expect(data).toEqual({ id: 1 })
})
// Promise matchers - ALWAYS await these
await expect(fetchData()).resolves.toEqual({ id: 1 })
await expect(fetchData()).rejects.toThrow('Error')
// Wrong - creates false positive
expect(promise).resolves.toBe(value) // Missing await!
Quick Mock Reference
const mockFn = vi.fn()
mockFn.mockReturnValue(42)
mockFn.mockResolvedValue({ data: 'value' })
expect(mockFn).toHaveBeenCalled()
expect(mockFn).toHaveBeenCalledWith('arg1', 'arg2')
expect(mockFn).toHaveBeenCalledTimes(2)
For vi.hoisted(), vi.mock(), importOriginal, and mock cleanup, see references/mocking.md.
Verification gates
Use this sequence when you add or change tests; each step has an objective pass condition.
- Run the test suite — From the package or workspace root, run the same command CI uses (check
package.jsonscripts; oftenvitest run,pnpm test, ornpm test). Pass: exit code is 0 and the report shows zero failing tests. - Async matchers — Pass: every
expect(…).resolvesandexpect(…).rejectsis prefixed withawait(await expect(...)), as in Async Testing. A line whereresolvesorrejectsappears withoutawaitfails this gate. - Vitest v4 config compatibility — Pass: config uses top-level
maxWorkers/isolate/fileParallelism(not removed v3poolOptions), explicitcoverage.includefor AST coverage, and@vitest/browser-playwright(provider: playwright()) if Browser Mode is configured.
Additional Documentation
- Mocking: See references/mocking.md for
vi.hoisted(), module mocking, spying, and cleanup - Configuration: See references/config.md for Vitest v4
vitest.config, workers, Browser Mode, and coverage - Patterns: See references/patterns.md for timers, snapshots, and anti-patterns
Test Methods Quick Reference
| Method | Purpose |
|---|---|
it() / test() |
Define test |
describe() |
Group tests |
beforeEach() / afterEach() |
Per-test hooks |
beforeAll() / afterAll() |
Per-suite hooks |
.skip |
Skip test/suite |
.only |
Run only this |
.todo |
Placeholder |
.concurrent |
Parallel execution |
.each([...]) |
Parameterized tests |
Установить vitest-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл vitest-testing?
Vitest v4 testing patterns, configuration, mocking, and verification gates. Use when writing unit or integration tests, configuring vitest.config, mocking modules with vi.mock/vi.hoisted/vi.fn, setting up coverage, or configuring Browser Mode.
Как установить скилл vitest-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл vitest-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic