Vitest | Sheetly Cheat Sheet

Last Updated: November 21, 2025

Vitest

Fast Vite-native unit testing

Core Features

Item Description
Vite Integration Native Vite support
Jest Compatible Similar API to Jest
Fast Powered by Vite and esbuild
ESM First ES modules by default
TypeScript Built-in TypeScript
Watch Mode Fast HMR-like reruns

Basic Test

import { describe, it, expect, beforeEach } from 'vitest'

describe('Math operations', () => {
  it('should add numbers', () => {
    expect(1 + 1).toBe(2)
  })

  it('should multiply', () => {
    expect(2 * 3).toBe(6)
  })
})

// Async tests
it('fetches data', async () => {
  const data = await fetchUser(1)
  expect(data.name).toBe('John')
})

// Mock
import { vi } from 'vitest'
const mockFn = vi.fn()
mockFn('hello')
expect(mockFn).toHaveBeenCalledWith('hello')

Common Commands

npm install -D vitest
Install Vitest
vitest
Run tests in watch mode
vitest run
Run tests once
vitest --coverage
Generate coverage report
vitest --ui
Open web UI

Best Practices

  • Use describe blocks to organize tests
  • Mock external dependencies
  • Use beforeEach for setup
  • Keep tests focused and isolated

💡 Pro Tips

Quick Reference

Vitest is 10x faster than Jest for Vite projects

← Back to Data Science & ML | Browse all categories | View all cheat sheets