diff --git a/packages/vitest/src/runtime/mocker.ts b/packages/vitest/src/runtime/mocker.ts index 8b818bd8b399..43c0f9e1ebcc 100644 --- a/packages/vitest/src/runtime/mocker.ts +++ b/packages/vitest/src/runtime/mocker.ts @@ -5,7 +5,7 @@ import { isNodeBuiltin } from 'vite-node/utils' import { getWorkerState } from '../utils/global' import { getAllMockableProperties } from '../utils/base' import type { MockFactory, PendingSuiteMock } from '../types/mocker' -import { spyOn } from '../integrations/spy' +import { fn as spy } from '../integrations/spy' import type { VitestExecutor } from './execute' const filterPublicKeys = ['__esModule', Symbol.asyncIterator, Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator, Symbol.match, Symbol.matchAll, Symbol.replace, Symbol.search, Symbol.split, Symbol.species, Symbol.toPrimitive, Symbol.toStringTag, Symbol.unscopables] @@ -271,20 +271,9 @@ export class VitestMocker { // Sometimes this assignment fails for some unknown reason. If it does, // just move along. - if (!define(newContainer, property, isFunction ? value : {})) + if (!define(newContainer, property, isFunction ? spy() : {})) continue - if (isFunction) { - const mock = spyOn(newContainer, property).mockImplementation(() => undefined) - mock.mockRestore = () => { - mock.mockReset() - mock.mockImplementation(undefined!) - return mock - } - // tinyspy retains length, but jest doesn't. - Object.defineProperty(newContainer[property], 'length', { value: 0 }) - } - refs.track(value, newContainer[property]) mockPropertiesOf(value, newContainer[property]) }