Closed AldeonMoriak closed 2 years ago
Hey, the timer is using requestAnimationFrame internally to measure the time and it seems useFakeTimers is not mocking that. You will need to find other way to test it.
Thank you. I was able to find a solution for that:
let count = 0;
vi.spyOn(window, "requestAnimationFrame").mockImplementation((cb) =>
setTimeout(() => cb(1000 * ++count), 100)
);
act(() => {
vi.advanceTimersByTime(6100);
});
Hello, these few days I've been trying to test a component which in it I have a countdown but I couldn't make countdown run in it. First I noticed it was a problem with not letting
vitest
knowDOM
has been updated so I addedact
to let it know. And I tested it by using asetInterval
in a test component. But stillcountdown
doesn't work in a test.I've created a minimal reproduction of the issue in here.
The component:
the test:
In this test
count
value gets updated but thecountdown
doesn't.