-
Notifications
You must be signed in to change notification settings - Fork 4
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
verifyAllMocksCalled
functionality
#12
Comments
Hi @buck06191! I'm opposed to Philosophical I think reliance on
Technical Implementating
Userland Not everyone has the same stubbing philosophy as me, and that's ok! While I am unwilling to implement this feature in Personally, I think Are there any APIs you could imagine that would help implement a stub registry in your suite - that you would be responsible for managing cleanup of yourself - to give yourself the ability to loop through all your stubs to check them? |
I think a fixture like this in your own codebase could work to replicate // when.ts
import { afterEach, expect } from 'vitest'
import { when as baseWhen } from 'vitest-when'
const mockRegistry = new Set()
export const when: typeof baseWhen = (spy, options) => {
const result = baseWhen(spy, options)
mockRegistry.add(spy)
return result
}
afterEach(() => {
const mocks = [...mockRegistry]
mockRegistry.clear()
for (const mock of mocks) {
expect(mock).toHaveBeenCalled()
}
}) Then, in your tests, import |
@buck06191 thanks for taking the time to write this request! After giving it some additional thought over the weekend - and after landing #11 - I don't think this feature is a good fit for this library. I'd like to keep Let me know if the above example is able to get you where you need to go, or if there are additional stub-level APIs that could be added to help you implement what you're trying to do |
What
In
jest-when
there's a feature we use at our company that verifies all of thewhen
mocks are called by the end of a test -https://github.com/timkindberg/jest-when/blob/master/src/when.js#L216In order for us to migrate to vitest it would be really good to have this added in to
vitest-when
.Do you think this is something you'd consider adding in? We could look at raising a PR ourselves as a proposal if that's the case
The text was updated successfully, but these errors were encountered: