How to test the side effect of a watcher function?
I have a component that looks something like this:
In my test, I'd like to assert that the change that happens in the e() function is done.
So far, I see the change that happens in the watch happen, and the side effect from running e(). However when I try to assert the textContent has changed due to the call, I am stuck.
edit: used flushPromises to pass assertion
3 Replies
Ah, I guess
flushPromises()
does work here. This was an attempt for a minimal reproduction but I still have work to do in my actual file since flushPromises doesn't seem to be enough
seems to be because of that weirdness with registerEndpoints not working when there are multiple endpoints being mocked, and they aren't mocked in the exact order they are called.. 😦Maybe this boils down to a pinia issue. I have this test that is failing: https://stackblitz.com/edit/nuxt-starter-k48kf2?file=tests%2Fapi.test.ts
Basically the fetch call in the store isn't awaited with
flushPromises
David Marr
StackBlitz
Nuxt - Starter (forked) - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
This is the only way I got my assertions to work when testing a watcher
you can change the timeout to whatever would be more appropriate for you, in this case it's a debounced watcher