Skip to content

Commit

Permalink
Add new tests to assert 29.3 behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
robhogan committed Aug 21, 2023
1 parent 56ddb9f commit 436f518
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/jest-mock/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 436f518

Please sign in to comment.