You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to test a polling component. Essentially the component re-fetches a status every 5s until the status becomes ready.
To that effect, I use msw polling mocking in conjunction with vi.runAllTimersAsync().
This works but triggers An update to ... inside a test was not wrapped in act(...) warnings. Wrapping the async timer in act essentially cancels it out, and the test times out.
I managed to do a minimal repro that doesn't involve msw or RTK to confirm the warning is indeed coming from the fake timer.
So far my only fix is to silence the warning 😅
Thanks for any help!
import{describe,expect,it}from'vitest';import{Button}from'./Button';import{render,screen}from'./utils/test-utils';describe('Simple working test',()=>{it('should refetch status when deploying until ready',async()=>{render(<Button/>);console.log('[before sleep 2sec]');awaitnewPromise((r)=>setTimeout(r,2000));console.log('[after sleep 2sec]');expect(awaitscreen.findByText('Stop')).toBeInTheDocument();});});
Describe the bug
I am attempting to test a polling component. Essentially the component re-fetches a status every 5s until the status becomes ready.
To that effect, I use
msw
polling mocking in conjunction withvi.runAllTimersAsync()
.This works but triggers
An update to ... inside a test was not wrapped in act(...)
warnings. Wrapping the async timer inact
essentially cancels it out, and the test times out.I managed to do a minimal repro that doesn't involve msw or RTK to confirm the warning is indeed coming from the fake timer.
So far my only fix is to silence the warning 😅
Thanks for any help!
Reproduction
https://stackblitz.com/edit/vitest-fake-timers-act-warnings
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: