Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support varargs in toHaveBeenCalledOnceWith (closes #517) #557

Merged
merged 1 commit into from Feb 2, 2023
Merged

Conversation

keeganwitt
Copy link
Collaborator

No description provided.

@keeganwitt
Copy link
Collaborator Author

I'm not sure this is the right way to solve this. It doesn't seem right...

@codecov
Copy link

codecov bot commented Jan 31, 2023

Codecov Report

Merging #557 (dacef88) into main (6fbb99e) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #557   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           73        73           
  Lines          673       673           
  Branches       289       289           
=========================================
  Hits           673       673           
Impacted Files Coverage 螖
src/matchers/toHaveBeenCalledOnceWith.js 100.00% <100.00%> (酶)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

src/matchers/toHaveBeenCalledOnceWith.js Show resolved Hide resolved
@@ -16,7 +16,9 @@ export function toHaveBeenCalledOnceWith(received, expected) {
}

const passOnce = received.mock.calls.length === 1;
const pass = passOnce && this.equals(expected, received.mock.calls[0][0]);
const mockCall = received.mock.calls[0];
const receivedArray = Array.isArray(mockCall) ? mockCall : [mockCall];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked createToBeCalledWithMatcher implementation in jest:
image

And I've tried using mockCall directly without converting it to array and it seems to pass all your tests:

image

@Maxim-Mazurok
Copy link

I'm not sure this is the right way to solve this. It doesn't seem right...

Not sure what exactly seems not right, perhaps my second suggestion will make it seem right? Haven't touched much of jest internals tho, so I probably don't know better.

@Maxim-Mazurok
Copy link

Thanks so much! Looking forward to getting this published to npm, cheers!

This was referenced Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants