diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index 0b03678c4040..3d534545dff9 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -1260,6 +1260,15 @@ describe('moduleMocker', () => { expect(mock.mock).not.toHaveProperty('lastCall'); }); + test('mockReset should be called on dispose', () => { + const mock = jest.fn(); + mock('first'); + mock('last', 'call'); + mock[Symbol.dispose](); + expect(mock.mock.calls).toEqual([]); + expect(mock.mock).not.toHaveProperty('lastCall'); + }); + test('mockName gets reset by mockReset', () => { const fn = jest.fn(); expect(fn.getMockName()).toBe('jest.fn()'); diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index b9582dbf8734..5d056fbc5050 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -800,8 +800,8 @@ export class ModuleMocker { }; f.withImplementation = withImplementation.bind(this); - if (Symbol.dispose) { - f[Symbol.dispose] = f.mockRestore; + if (this._environmentGlobal.Symbol.dispose) { + f[this._environmentGlobal.Symbol.dispose] = f.mockRestore; } function withImplementation(fn: T, callback: () => void): void;