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

Function doMock

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

Source from the content-addressed store, hash-verified

660 },
661
662 doMock(path: string | Promise<unknown>, factory?: MockOptions | MockFactoryWithHelper) {
663 if (typeof path !== 'string') {
664 throw new TypeError(
665 `vi.doMock() expects a string path, but received a ${typeof path}`,
666 )
667 }
668 const importer = getImporter('doMock')
669 _mocker().queueMock(
670 path,
671 importer,
672 typeof factory === 'function'
673 ? () =>
674 factory(() =>
675 _mocker().importActual(
676 path,
677 importer,
678 _mocker().getMockContext().callstack,
679 ),
680 )
681 : factory,
682 )
683
684 const rv = {} as Disposable
685 if (Symbol.dispose) {
686 rv[Symbol.dispose] = () => {
687 _mocker().queueUnmock(path, importer)
688 }
689 }
690 return rv
691 },
692
693 doUnmock(path: string | Promise<unknown>) {
694 if (typeof path !== 'string') {

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…