-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Test hangs waiting for promise to resolve #621
Comments
Problem is caused by your usage of |
What's the approach when using a real api call? https://stackblitz.com/edit/github-u4au2p-urgmzt?file=src/stores/counter.js |
You can follow guide from the docs or use any kind of mocking library to mock globalThis.fetch = vi.fn().mockReturnValue(data) |
Yeah I know I can mock fetch or library but I'm actually using MSW to avoid having to mock all my requests. |
That is what our guide recommends. |
Yeah and With Jest I could just do: jest.useFakeTimers('modern').setSystemTime(nee Date('2020-01-01')) and it didn't hang. If I understood correctly by using |
Usually no, It shouldn't, if implementation doesn't have something like The issue happens only with MSW? We are using the same API jest uses, so I struggle to see where it came from. |
Hanging actually comes from |
Maybe you were using another package for fetch? Happy-dom uses
This is expected behaviour, unfortunately. I recommend using |
I'm using Axios
Thanks I will use Thank once again for your help 👍 |
@sheremet-va would it be a good idea to bring back |
I do agree it's an overkill, but don't like having two methods for this. We can use |
That is a great idea. |
Co-authored-by: Anthony Fu <[email protected]>
Describe the bug
Using the new
vi.setSystemTime
I addedvi.useFakeTimers();
but this seems to be breaking my async tests.The tests now wait for the promise to resolve, and since we are using fake timers it never happens.
I saw an example that uses
await flushPromises()
but this doesn't seem to do the trick.Reproduction
https://stackblitz.com/edit/github-u4au2p?file=src/stores/counter.js
Run
yarn test
and see the test hangSystem Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: