Skip to content

Commit 6d5fbff

Browse files
authored
Use vi.stubGlobal for requestAnimationFrame (#6393)
# 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
1 parent 742222e commit 6d5fbff

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

frontend/vitest.setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ vi.mock("$app/stores", () => ({
195195
}));
196196

197197
// Issue: https://github.com/testing-library/svelte-testing-library/issues/206
198-
Object.defineProperty(global, "requestAnimationFrame", {
199-
value: (fn) => {
198+
beforeEach(() => {
199+
vi.stubGlobal("requestAnimationFrame", (fn) => {
200200
return window.setTimeout(() => fn(Date.now()), 0);
201-
},
201+
});
202202
});

0 commit comments

Comments
 (0)