Clear, Reset & Restore in Vitest
From the Vitest cheat sheet ยท Mock Functions ยท verified Nov 2026
Clear, Reset & Restore
Reset mock state between tests and understand the Vitest 5 clearMocks default
typescript
fn.mockClear() // forget calls, keep implementation
fn.mockReset() // forget calls + reset to the original impl
spy.mockRestore() // reset + put the real method back (spyOn)
vi.clearAllMocks()
vi.resetAllMocks()
vi.restoreAllMocks()๐ v5 turns clearMocks on by default; set it false for v4 behavior
โ ๏ธ Calls recorded in beforeAll or at module level are now cleared
๐ Unlike Jest, mockReset restores vi.fn(impl) to impl, not a no-op
๐ฏ restoreMocks: true is a safe default if you use vi.spyOn a lot
mockClearmockResetmockRestoreclearMocks
Continue with Vitest
Save the full cheat sheet or work through every related task.