Skip to content

Structured guide of Vitest patterns covering unit and integration tests, assertions, async handling, and mocking.

CCM score
48 of 100
skills.sh installs
473
GitHub stars
91
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers writing unit and integration tests with describe, it, expect, and per-test and per-suite hooks
  • Includes quick references for common assertions, async testing, vi.fn mocks, and a table of test methods such as .each and .concurrent
  • Enforces await on every expect(...).resolves and expect(...).rejects, and a passing suite run before changes are accepted
  • Points to separate references for module mocking, vitest.config and coverage setup, and timers, snapshots, and anti-patterns

Install

$ npx -y skills add existential-birds/beagle --skill vitest-testing -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

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 })
})

Details

Repository
github.com/existential-birds/beagle
Categories
Testing & QA, Frontend & UI Code
First seen
Jun 3, 2026

More from existential-birds/beagle

All 37

Similar to Vitest Testing

More Testing & QA