Vitest · Function
vi.spyOn
vi.spyOn tracks calls to an object method or accessor while letting you keep or change its behavior. It returns a mock function that can be configured and restored.
Last updated
Syntax
function spyOn<T, K extends keyof T>(object: T, key: K, accessor?: 'get' | 'set'): Mock<T[K]>In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
vi.fnvi.mockvi.mockedvi.clearAllMocksvi.resetAllMocksvi.restoreAllMocks