From fa68b7f42edca8eeab19e1850a3ae768edab3d34 Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Thu, 29 Oct 2020 09:20:06 +0000 Subject: [PATCH] fix matching exact args --- src/when.js | 2 +- src/when.test.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/when.js b/src/when.js index bf69246..8df777a 100644 --- a/src/when.js +++ b/src/when.js @@ -68,7 +68,7 @@ class WhenMock { if (once && called) continue const isMatch = - args.length <= matchers.length && + args.length === matchers.length && matchers.reduce(checkArgumentMatchers(expectCall, args), true) if (isMatch) { diff --git a/src/when.test.js b/src/when.test.js index d3ae397..3e6124d 100644 --- a/src/when.test.js +++ b/src/when.test.js @@ -160,7 +160,7 @@ describe('When', () => { const anyString = expect.any(String) when(fn) - .calledWith(1, 'foo', true, anyString, undefined) + .calledWith(1, 'foo', true, anyString) .mockReturnValue('x') expect(fn(1, 'foo', true, 'whatever')).toEqual('x') @@ -168,7 +168,6 @@ describe('When', () => { expect(spyEquals).toBeCalledWith('foo', 'foo') expect(spyEquals).toBeCalledWith(true, true) expect(spyEquals).toBeCalledWith('whatever', anyString) - expect(spyEquals).toBeCalledWith(undefined, undefined) }) it('only matches exact sets of args, too little or too many args do not trigger mock return', () => { @@ -178,7 +177,7 @@ describe('When', () => { .calledWith(1, 'foo', true, expect.any(String), undefined) .mockReturnValue('x') - expect(fn(1, 'foo', true)).toEqual(undefined) + expect(fn(1, 'foo', true, 'whatever')).toEqual(undefined) expect(fn(1, 'foo', true, 'whatever', undefined, 'oops')).toEqual(undefined) })