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 toHaveBeenCalledOnceWith matcher #430
Add toHaveBeenCalledOnceWith matcher #430
Conversation
e8e857f
to
fdf3e18
Compare
Codecov Report
@@ Coverage Diff @@
## main #430 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 71 72 +1
Lines 582 594 +12
Branches 148 151 +3
=========================================
+ Hits 582 594 +12
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
I think it'd be more flexible to do this using the existing matchers. For example, const arg = 1;
mock(arg);
expect(mock).toHaveBeenCalledOnce();
expect(mock.mock.calls[0][0]).toEqual(arg);
// or expect(mock.mock.lastCall[0]).toEqual(arg);
// or expect(mock.mock.invocationCallOrder[0]).toEqual(arg); Using this pattern, you can use |
Hey @keeganwitt! Thank you for taking the time to comment the PR. I do agree that having a
|
Thank you for the suggestion and the PR (sorry I forgot to say that earlier)! The fact Jest's own |
I think it makes sense to have this matcher if we've got |
I'm trying to find the underlying matcher in I think we should confirm if the checks there are the equivalent to |
Hi there I thought about having a util function in our company codebase that is called How is this different from the proposed implementation here? |
It would do the same thing. So would |
I'm wondering if it'd maybe be better to change this to |
@keeganwitt I think that toHaveBeenCalledNTimesWith could be a separate matcher, but I'd hate to conflate it with this feature personally. In my personal experience, toHaveBeenCalledOnceWith is a much more common use-case. Also, if we wanted to consider toHaveBeenCalledNTimesWith, we're going to have to have the discussion of how the expected argument works. "Can I pass multiple arguments as Also, I personally think that toHaveBeenCalledOnceWith feels "discoverable". If I needed toHaveBeenCalledNTimesWith, I wouldn't have found it by just expecting it to be there / guessing the name. I think that says something about toHaveBeenCalledOnceWith having value even if it ended up just wrapping a toHaveBeenCalledNTimesWith matcher. That feels like a completely separate discussion / issue to me. |
@thibautsabot FYI it looks like this was approved 😺 |
I'm pretty sure those are the same. |
fdf3e18
to
a898bd0
Compare
a898bd0
to
b5096b0
Compare
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [jest-extended](https://togithub.com/jest-community/jest-extended) | [`3.0.2` -> `3.1.0`](https://renovatebot.com/diffs/npm/jest-extended/3.0.2/3.1.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>jest-community/jest-extended</summary> ### [`v3.1.0`](https://togithub.com/jest-community/jest-extended/releases/tag/v3.1.0) [Compare Source](https://togithub.com/jest-community/jest-extended/compare/v3.0.2...v3.1.0) #### What's Changed - Add toHaveBeenCalledOnceWith matcher by [@​thibautsabot](https://togithub.com/thibautsabot) in [jest-community/jest-extended#430 - docs: mention `eslint-plugin-jest-extended` in README by [@​G-Rath](https://togithub.com/G-Rath) in [jest-community/jest-extended#493 - Update jest monorepo to v29 (major) by [@​renovate](https://togithub.com/renovate) in [jest-community/jest-extended#495 #### New Contributors - [@​thibautsabot](https://togithub.com/thibautsabot) made their first contribution in [jest-community/jest-extended#430 **Full Changelog**: jest-community/jest-extended@v3.0.2...v3.1.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/BirthdayResearch/sticky). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xODQuMiIsInVwZGF0ZWRJblZlciI6IjMyLjIwNC41In0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
I like that this matcher exists but am surprised by it only supporting one expected value. Native Ironically, #518 moved things in the opposite direction. |
What
Add toHaveBeenCalledOnceWith matcher
Why
To fix the second part of #138
Housekeeping