I am using Jest along with react-testing-library, and encountered this warning when simulating advancing the timer:
console.error
Warning: An update to TimerProvider inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
After some searching, I found a video suggesting wrapping any calls to jest.advanceTimersByTime in the act() function.
act(() => jest.advanceTimesByTime(1000);
However I am using TypeScript and am now confused as to how to resolve the resultant type error:
TS2769:Type 'typeof jest' is not assignable to type 'void'.
How do I fix this type error correctly?