Common Matchers in Vitest
From the Vitest cheat sheet ยท Assertions ยท verified Nov 2026
Common Matchers
Equality, truthiness, numbers, strings, collections, types, and errors
typescript
expect(2 + 2).toBe(4) // Object.is
expect(user).toEqual({ id: 1, name: 'Ada' }) // deep equality
expect(user).toMatchObject({ name: 'Ada' }) // subset
expect(list).toContain('apple')
expect(list).toHaveLength(3)
expect(0.1 + 0.2).toBeCloseTo(0.3)
expect(() => parse('')).toThrow('empty input')๐ toBe uses Object.is; use toEqual for objects and arrays
๐ toStrictEqual also checks undefined props, sparse arrays and classes
โ ๏ธ toThrow needs a function wrapper: expect(() => fn()).toThrow()
๐ก toThrowError is a deprecated alias in v5; use toThrow
expectmatcherstoEqualtoThrow
Continue with Vitest
Save the full cheat sheet or work through every related task.