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

feat(expect): add toHaveBeenCalledExactlyOnceWith expect matcher #6894

Merged

Conversation

jacoberdman2147
Copy link
Contributor

@jacoberdman2147 jacoberdman2147 commented Nov 11, 2024

Description

This PR adds an expect.toHaveBeenCalledOnceWith method which asserts that a method has been called with the given arguments and has been called exactly once.

This fixes #6849

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit f137bbe
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/6734cd236cefd70008b4f204
😎 Deploy Preview https://deploy-preview-6894--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Nov 12, 2024

Thanks for picking this up! I didn't mention it in the issue, but probably we can just use toHaveBeenCalledExactlyOnceWith naming from jest-extend (for alignment and for explicitness). Do you see any reason not to do that?

Other than that, the code looks good to me 👍

@hi-ogawa hi-ogawa added this to the 2.2.0 milestone Nov 12, 2024
@jacoberdman2147
Copy link
Contributor Author

Ah yeah, I was on the fence about naming, the more official doc I found suggested it should be toHaveBeenCalledExactlyOnceWith but I felt like I saw more references to toHaveBeenCalledOnceWith and just went with it because it was in the issue title. I'll quickly rename it.

…th to better fit in with the current ecosystem
@jacoberdman2147 jacoberdman2147 changed the title feat(expect): add toHaveBeenCalledOnceWith expect matcher feat(expect): add toHaveBeenCalledExactlyOnceWith expect matcher Nov 12, 2024
hi-ogawa
hi-ogawa previously approved these changes Nov 12, 2024
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Thanks!

@jacoberdman2147
Copy link
Contributor Author

This is my first time putting a PR up on Github, how do I actually merge the PR now that it's approved and such?

@hi-ogawa
Copy link
Contributor

The exact process depends on project, but in our case, your change is a new feature, so we'll wait until next minor release. That's why I put it in 2.2.0 milestone https://github.com/vitest-dev/vitest/milestone/21

docs/api/expect.md Outdated Show resolved Hide resolved
@sheremet-va sheremet-va merged commit ff66206 into vitest-dev:main Nov 13, 2024
14 checks passed
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.

New assertion matcher "toHaveBeenCalledOnceWith"
3 participants