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

Function mock

packages/vitest/src/integrations/vi.ts:630–651  ·  view source on GitHub ↗
(path: string | Promise<unknown>, factory?: MockOptions | MockFactoryWithHelper)

Source from the content-addressed store, hash-verified

628 },
629
630 mock(path: string | Promise<unknown>, factory?: MockOptions | MockFactoryWithHelper) {
631 if (typeof path !== 'string') {
632 throw new TypeError(
633 `vi.mock() expects a string path, but received a ${typeof path}`,
634 )
635 }
636 const importer = getImporter('mock')
637 _mocker().queueMock(
638 path,
639 importer,
640 typeof factory === 'function'
641 ? () =>
642 factory(() =>
643 _mocker().importActual(
644 path,
645 importer,
646 _mocker().getMockContext().callstack,
647 ),
648 )
649 : factory,
650 )
651 },
652
653 unmock(path: string | Promise<unknown>) {
654 if (typeof path !== 'string') {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…