Mocking and Spying
Harness provides comprehensive mocking and spying capabilities through Vitest's @vitest/spy package. The API is 100% compatible with Vitest's spy and mock functionality.
Creating Mock Functions
fn()
Create a mock function that tracks calls, arguments, and return values.
Spying on Existing Methods
spyOn()
Create a spy that watches calls to an existing method while preserving the original implementation.
Mock Management
clearAllMocks()
Clear call history for all mocks while keeping their implementations.
resetAllMocks()
Reset all mocks to their initial state, clearing both call history and implementations.
restoreAllMocks()
Restore all spied methods to their original implementations.
Spy Assertions
Harness supports all Vitest spy assertions:
Complete API Reference
Harness provides the complete Vitest spy and mock API including:
- Mock Functions:
fn(), mock implementations, return values - Spying:
spyOn(), method restoration - Mock Management:
clearAllMocks(),resetAllMocks(),restoreAllMocks() - Spy Assertions: All
toHaveBeenCalled*andtoHaveReturned*matchers
For module mocking capabilities, see the Module Mocking documentation.
