Your First Test in Vitest
From the Vitest cheat sheet · Setup & Configuration · verified Nov 2026
Your First Test
Write a test file Vitest picks up by default and read the output
typescript
// sum.ts
export const sum = (a: number, b: number) => a + b
// sum.test.ts
import { expect, test } from 'vitest'
import { sum } from './sum'
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})🟢 Files need .test. or .spec. in the name to be collected by default
📌 Import test, expect and vi from vitest; globals are off by default
⚡ TypeScript and JSX work out of the box through Vite, no ts-jest
💡 Keep tests next to source files or in a tests/ folder; both work
basicsfirst-test
Continue with Vitest
Save the full cheat sheet or work through every related task.