Jest / Vitest assertions
Updated 2026-02-15
expect(), matchers, and async tests. toBe, toEqual, toThrow, and mocking basics.
expect matchers
expect(x).toBe(y) strict equal. expect(x).toEqual(y) deep. expect(x).toBeNull(), toBeDefined(), toBeTruthy(). expect(n).toBeGreaterThan(1). expect(arr).toContain(item). expect(fn).toThrow().
Async and mock
await expect(promise).resolves.toBe(val). jest.fn(), mock.mockReturnValue(1), mock.mockResolvedValue(1). vi.fn() in Vitest. describe, it, beforeEach.