vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
13.13k stars 1.18k forks source link

feat(expect): add `toHaveBeenCalledExactlyOnceWith` expect matcher #6894

Closed jacoberdman2147 closed 1 week ago

jacoberdman2147 commented 2 weeks ago

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:

Tests

Documentation

Changesets

netlify[bot] commented 2 weeks ago

Deploy Preview for vitest-dev ready!

Name Link
Latest commit f137bbe1cdf6ebfd6947b42e9e0641a0be23f71c
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 commented 2 weeks ago

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 :+1:

jacoberdman2147 commented 1 week ago

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.

jacoberdman2147 commented 1 week ago

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 commented 1 week ago

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