Skip to content

Commit 436f518

Browse files
committed
Add new tests to assert 29.3 behaviour
1 parent 56ddb9f commit 436f518

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/jest-mock/src/__tests__/index.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,26 @@ describe('moduleMocker', () => {
598598
expect(fn2()).not.toBe('abcd');
599599
});
600600

601+
it('is not affected by restoreAllMocks', () => {
602+
const fn1 = moduleMocker.fn();
603+
fn1.mockImplementation(() => 'abcd');
604+
fn1(1, 2, 3);
605+
expect(fn1.mock.calls).toEqual([[1, 2, 3]]);
606+
moduleMocker.restoreAllMocks();
607+
expect(fn1(1)).toBe('abcd');
608+
expect(fn1.mock.calls).toEqual([[1, 2, 3], [1]]);
609+
});
610+
611+
it('is cleared and stubbed when restored explicitly', () => {
612+
const fn1 = moduleMocker.fn();
613+
fn1.mockImplementation(() => 'abcd');
614+
fn1(1, 2, 3);
615+
expect(fn1.mock.calls).toEqual([[1, 2, 3]]);
616+
fn1.mockRestore();
617+
expect(fn1(1)).toBeUndefined();
618+
expect(fn1.mock.calls).toEqual([[1]]);
619+
});
620+
601621
it('maintains function arity', () => {
602622
const mockFunctionArity1 = moduleMocker.fn(x => x);
603623
const mockFunctionArity2 = moduleMocker.fn((x, y) => y);

0 commit comments

Comments
 (0)