Skip to content

Commit

Permalink
Merge pull request #55 from tjenkinson/fix-matching-exact-args
Browse files Browse the repository at this point in the history
fix matching exact args
  • Loading branch information
timkindberg authored Nov 1, 2020
2 parents b03f83b + 88f5e2b commit d4f496f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/when.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/when.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('When', () => {
.calledWith(1, 'foo', true, anyString, undefined)
.mockReturnValue('x')

expect(fn(1, 'foo', true, 'whatever')).toEqual('x')
expect(fn(1, 'foo', true, 'whatever', undefined)).toEqual('x')
expect(spyEquals).toBeCalledWith(1, 1)
expect(spyEquals).toBeCalledWith('foo', 'foo')
expect(spyEquals).toBeCalledWith(true, true)
Expand All @@ -178,7 +178,10 @@ 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', undefined)).toEqual('x')

expect(fn(1, 'foo', true, 'whatever')).toEqual(undefined)
expect(fn(1, 'foo', true, 'whatever', undefined, undefined)).toEqual(undefined)
expect(fn(1, 'foo', true, 'whatever', undefined, 'oops')).toEqual(undefined)
})

Expand Down

0 comments on commit d4f496f

Please # to comment.