diff --git a/src/CalledWithFn.ts b/src/CalledWithFn.ts index db5bb12..44b3730 100644 --- a/src/CalledWithFn.ts +++ b/src/CalledWithFn.ts @@ -45,7 +45,7 @@ export const calledWithFn = (): CalledWithMock => { fn.mockImplementation((...args: Y) => checkCalledWith(calledWithStack, args)); calledWithStack = []; } - calledWithStack.push({ args, calledWithFn }); + calledWithStack.unshift({ args, calledWithFn }); return calledWithFn; }; diff --git a/src/Mock.spec.ts b/src/Mock.spec.ts index b0b3591..8a976d8 100644 --- a/src/Mock.spec.ts +++ b/src/Mock.spec.ts @@ -205,6 +205,14 @@ describe('jest-mock-extended', () => { expect(mockObj.getSomethingWithArgs(7, 2)).toBe(undefined); }); + test('supports overriding with same args', () => { + const mockObj = mock(); + mockObj.getSomethingWithArgs.calledWith(1, 2).mockReturnValue(4); + mockObj.getSomethingWithArgs.calledWith(1, 2).mockReturnValue(3); + + expect(mockObj.getSomethingWithArgs(1, 2)).toBe(3); + }) + test('Support jest matcher', () => { const mockObj = mock(); mockObj.getSomethingWithArgs.calledWith(expect.anything(), expect.anything()).mockReturnValue(3);