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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last 3 actual calls for toBeCalledWith message #987

Closed
wants to merge 1 commit into from

Conversation

petetnt
Copy link
Contributor

@petetnt petetnt commented May 10, 2016

This PR continues from #918 and fixes #954 by adding the last 3 (or less) actual values that were called to the error message when using toBeCalledWith

Details:

  • If there are less or exactly 3 calls, it just shows the 3 calls comma separated
  • If there's exactly 4 calls, it appends and 1 other call to the message
  • If there's more than 4 calls, it appends and X other calls to the message (when X is the amount > 3)
  • The calls are sliced from the end of the calls array and the messages are reversed so they appear in "correct" order.

Tests included (plus 2 typo fixes in the same test file :neckbeard:)

Ping @cpojer

Signed-off-by: petetnt <pete.a.nykanen@gmail.com>
@cpojer
Copy link
Member

cpojer commented May 11, 2016

This is fantastic! I'll land it tomorrow :)

Should we also do this or something similar for lastCalledWith (and potentially factor the code out into a reusable piece)?

@petetnt
Copy link
Contributor Author

petetnt commented May 11, 2016

I was thinking about the lastCalledWith case, I think that the current implementation (of showing the last call only) is correct but I think that the message should be something like Wasn't called last with the expected values.\n instead of just Wasn't called with the expected values.\n for extra clarity (ditto for the not called-message few lines below).

Then again showing the last X calls could have some extra merit for debugging purposes for lastCalledWith too.

@cpojer
Copy link
Member

cpojer commented May 11, 2016

@facebook-github-bot import

@ghost
Copy link

ghost commented May 11, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review.

@cpojer
Copy link
Member

cpojer commented May 12, 2016

@facebook-github-bot shipit

@ghost
Copy link

ghost commented May 12, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in 88b7d59 May 12, 2016
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

toBeCalledWith and lastCalledWith should print some of the call values.
2 participants