From 436f51808c8ece23f168827037ceb92f613baf9a Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Thu, 17 Aug 2023 17:04:03 +0100 Subject: [PATCH] Add new tests to assert 29.3 behaviour --- .../jest-mock/src/__tests__/index.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index 1beaecb7c7cd..c0efe908e7d9 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -598,6 +598,26 @@ describe('moduleMocker', () => { expect(fn2()).not.toBe('abcd'); }); + it('is not affected by restoreAllMocks', () => { + const fn1 = moduleMocker.fn(); + fn1.mockImplementation(() => 'abcd'); + fn1(1, 2, 3); + expect(fn1.mock.calls).toEqual([[1, 2, 3]]); + moduleMocker.restoreAllMocks(); + expect(fn1(1)).toBe('abcd'); + expect(fn1.mock.calls).toEqual([[1, 2, 3], [1]]); + }); + + it('is cleared and stubbed when restored explicitly', () => { + const fn1 = moduleMocker.fn(); + fn1.mockImplementation(() => 'abcd'); + fn1(1, 2, 3); + expect(fn1.mock.calls).toEqual([[1, 2, 3]]); + fn1.mockRestore(); + expect(fn1(1)).toBeUndefined(); + expect(fn1.mock.calls).toEqual([[1]]); + }); + it('maintains function arity', () => { const mockFunctionArity1 = moduleMocker.fn(x => x); const mockFunctionArity2 = moduleMocker.fn((x, y) => y);