-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
p2-nice-to-haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)
Description
Clear and concise description of the problem
When testing code which relies on the browser's requestAnimationFrame method, it would be great to have the ability to advance fake timers by the amount needed to execute any scheduled animation frames. sinonjs/fake-timers supports this with the clock.runToFrame() method, which Jest exposes as jest.advanceTimersToNextFrame().
Suggested solution
vi.advanceTimersToNextFrame() could be introduced to mirror the Jest implementation. This would be straightforward to implement (I am happy to make a PR) and would increase compatibility between Jest and Vitest.
Example:
let frameRendered = false
vi.useFakeTimers({ toFake: 'requestAnimationFrame' })
requestAnimationFrame(() => {
frameRendered = true
})
vi.advanceTimersToNextFrame()
expect(frameRendered).toBe(true)Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Metadata
Metadata
Assignees
Labels
p2-nice-to-haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)