Replies: 1 comment 1 reply
-
Probably this is what you're looking for #6426 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using
vi.spyOn()
to spy or mock instance methods, for exampledatabase.query() calls
. In one test file, I have several tests and some tests should be able to execute the spied functiondatabase.query()
and I want to assert the invoked parameters, whereas in other test cases, I want to simply mock the returned value ofdatabase.query()
without executing a real database query.I noticed that if I use
vi.spyOn(Database.protoype, 'query').mockResolvedValue()
once, and the reset it viavi.restoreAllMocks()
or callingmockReset()
on the spy, it won't reset it to the actual implementation of calling thedatabase.query()
function.This is clearly described in the docs, so my obviously my bad:
https://vitest.dev/api/vi.html#vi-spyon
But I was still wondering what is the actual reason you cannot mock and reset a spy multiple times in one test file?
Beta Was this translation helpful? Give feedback.
All reactions