Skip to content

Use vi.stubGlobal for requestAnimationFrame #6393

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

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

dskloetd
Copy link
Contributor

Motivation

In #3483 we stubbed requestAnimationFrame to work around testing-library/svelte-testing-library#206

In #4695 we changed from vi.stubGlobal to Object.defineProperty because vi.unstubAllGlobals was undoing the workaround.

With Vitest 3, using Object.defineProperty to redefine requestAnimationFrame causes

TypeError: Cannot assign to read only property 'requestAnimationFrame' of object '#<Object>'

Instead we should go back to vi.stubGlobal but use it in beforeEach after vi.unstubAllGlobals so it's re-stubbed each time.

Changes

  1. Use vi.stubGlobal for requestAnimationFrame instead of Object.defineProperty and wrap it in beforeEach.

Tests

  1. Existing tests still pass.
  2. Tested in another branch with vitest updated to 3.0.5.

Todos

  • Add entry to changelog (if necessary).
    not necessary

@dskloetd dskloetd marked this pull request as ready for review February 11, 2025 10:31
@dskloetd dskloetd requested a review from a team as a code owner February 11, 2025 10:31
@dskloetd dskloetd enabled auto-merge February 11, 2025 10:31
Copy link
Member

@peterpeterparker peterpeterparker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thx

Copy link
Contributor

@yhabib yhabib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@dskloetd dskloetd added this pull request to the merge queue Feb 11, 2025
Merged via the queue into main with commit 6d5fbff Feb 11, 2025
32 checks passed
@dskloetd dskloetd deleted the kloet/requestAnimationFrame branch February 11, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants