MCPcopy
hub / github.com/vitest-dev/vitest / mock

Function mock

packages/mocker/src/browser/hints.ts:62–82  ·  view source on GitHub ↗
(path: string | Promise<unknown>, factory?: ModuleMockOptions | ModuleMockFactoryWithHelper)

Source from the content-addressed store, hash-verified

60 },
61
62 mock(path: string | Promise<unknown>, factory?: ModuleMockOptions | ModuleMockFactoryWithHelper): void {
63 if (typeof path !== 'string') {
64 throw new TypeError(
65 `vi.mock() expects a string path, but received a ${typeof path}`,
66 )
67 }
68 const importer = getImporter('mock')
69 _mocker().queueMock(
70 path,
71 importer,
72 typeof factory === 'function'
73 ? () =>
74 factory(() =>
75 _mocker().importActual(
76 path,
77 importer,
78 ),
79 )
80 : factory,
81 )
82 },
83
84 unmock(path: string | Promise<unknown>): void {
85 if (typeof path !== 'string') {

Callers 3

mocked.test.tsFile · 0.50
vi-fn.test.tsFile · 0.50

Calls 5

factoryFunction · 0.85
getImporterFunction · 0.70
_mockerFunction · 0.70
queueMockMethod · 0.65
importActualMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…