useMockFn
function in meocord/testing Since 4.2.0
useMockFn(factory: MockFnFactory): voidMakes every mock meocord/testing creates with the test runner's own mock function, such as Vitest's vi.fn.
Call it once in the runner's setup file. The runner then treats meocord's mocks as its own: its clearMocks and
mockReset config and vi.clearAllMocks() reach them, its matchers read them, and its whole mock API is there.
Without it, mocks are createMockFn's own, which jest's and Vitest's expect read too.
Parameters
| Name | Type | Description |
|---|---|---|
factory | MockFnFactory | The runner's mock function factory: |
Throws
Error when a mock already exists from another factory, or when
factorydoesn't make a mock with jest's and Vitest's API.
Examples
// vitest.setup.ts
import { vi } from 'vitest'
useMockFn(vi.fn)