With msw enabled, flushPromises
from vue-test-utils
must be called multiple times to wait for component render
#988
Replies: 4 comments 5 replies
-
Hey, @vincerubinetti. Thanks for raising this. Can you please share more info about the state of your app/test when you're using only one
When looking at the
const scheduler = typeof setImmediate === 'function' ? setImmediate : setTimeout
export function flushPromises() {
return new Promise((resolve) => {
scheduler(resolve, 0)
})
} This may have an implicit issue when using Fake timers in Jest. Make sure you're using fake timers correctly if you are. Could you please prepare a reproduction repository where I could look into this issue? That'd be the most efficient way for me to help you. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi all, I have also tried to use Vue + jest + unit test + msw + flushPromises but having similar problem. In my case, I needed to add 3 |
Beta Was this translation helpful? Give feedback.
-
Hi everyone! I was also wondering why I have to call |
Beta Was this translation helpful? Give feedback.
-
The amount of people commenting on this seems to warrant an actual issue. I'm going to create one from this discussion. |
Beta Was this translation helpful? Give feedback.
-
I have a Vue and vue-test-utils project that I'm trying to use MSW with. I have unit tests for components that call api functions when mounted. Vue exports a function called
flushPromises
, which is intended to be a simple function you can await to make sure the api calls have returned and the component has finished rendering before continuing with the test.The component that I'm testing looks like this:
For some reason, with MSW, I need two
flushPromises
calls for my tests to pass. The odd thing is, I was usingaxios-mock-adapter
before trying out MSW, and it was working with just one call. Can anyone think of any reason why MSW might be different?Another funny thing is that MSW is working in my e2e tests in Cypress (setupWorker), but the problem I describe above is happening in my unit tests in Jest (setupServer), which is setup like this:
Beta Was this translation helpful? Give feedback.
All reactions