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

Function fn

packages/spy/src/index.ts:244–260  ·  view source on GitHub ↗
(
  originalImplementation?: T,
)

Source from the content-addressed store, hash-verified

242}
243
244export function fn<T extends Procedure | Constructable = Procedure>(
245 originalImplementation?: T,
246): Mock<T> {
247 // if the function is already a mock, just return the same function,
248 // similarly to how vi.spyOn() works
249 if (originalImplementation != null && isMockFunction(originalImplementation)) {
250 return originalImplementation as Mock<T>
251 }
252
253 return createMockInstance({
254 // we pass this down so getMockImplementation() always returns the value
255 mockImplementation: originalImplementation,
256 // special case so that .mockReset() resets the value to
257 // the the originalImplementation instead of () => undefined
258 resetToMockImplementation: true,
259 }) as Mock<T>
260}
261
262export function spyOn<T extends object, S extends Properties<Required<T>>>(
263 object: T,

Callers 15

onCancelFunction · 0.50
cleanupFunction · 0.50
withSafeTimersFunction · 0.50
safeFunction · 0.50
withAwaitAsyncAssertionsFunction · 0.50
callTestHooksFunction · 0.50
callCleanupHooksFunction · 0.50
runTestFunction · 0.50
runWithSuiteFunction · 0.50
withTimeoutFunction · 0.50
withCancelFunction · 0.50
innerFnFunction · 0.50

Calls 2

createMockInstanceFunction · 0.85
isMockFunctionFunction · 0.70

Tested by

no test coverage detected