Skip to content
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

Add support for advancing timers to the next animation frame #6346

Closed
4 tasks done
bnjm opened this issue Aug 14, 2024 · 0 comments · Fixed by #6347
Closed
4 tasks done

Add support for advancing timers to the next animation frame #6346

bnjm opened this issue Aug 14, 2024 · 0 comments · Fixed by #6347
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@bnjm
Copy link
Contributor

bnjm commented Aug 14, 2024

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

@sheremet-va sheremet-va added p2-nice-to-have Not breaking anything but nice to have (priority) and removed enhancement: pending triage labels Aug 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants