Skip to content

Commit b9d7ad1

Browse files
test(core): fix flaky focusNode test by using fake timers for rAF (#15865)
jsdom polyfills requestAnimationFrame as setTimeout(cb, 16). The mountWithChart helper only awaited setTimeout(0) callbacks, so in CI poll() (which calls capturePositions) had not yet fired when selectNode was called, leaving storedPositions empty and causing focusNode to be skipped — a non-deterministic race. Replace the manual setTimeout(0) waits with vi.useFakeTimers() + vi.runAllTimersAsync() so the rAF callback fires before assertions run.
1 parent 034f749 commit b9d7ad1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

ui/tests/unit/dependencies/composables/useDependencies.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ describe("useDependencies composable", () => {
314314
],
315315
count: 3,
316316
});
317+
vi.useFakeTimers();
317318
const wrapper = mount({
318319
template: "<div></div>",
319320
setup() {
@@ -323,13 +324,14 @@ describe("useDependencies composable", () => {
323324
return {composable};
324325
},
325326
});
326-
// Flush microtasks (promise resolution + Vue reactivity) then
327-
// allow jsdom's setTimeout-based requestAnimationFrame to fire.
327+
// Flush microtasks (promise resolution + Vue reactivity) so onMounted's
328+
// async fetch resolves, then advance fake timers past jsdom's rAF polyfill
329+
// (setTimeout 16 ms) so capturePositions() runs and storedPositions is populated.
328330
await nextTick();
329331
await nextTick();
330-
await new Promise(resolve => setTimeout(resolve, 0));
331-
await new Promise(resolve => setTimeout(resolve, 0));
332+
await vi.runAllTimersAsync();
332333
await nextTick();
334+
vi.useRealTimers();
333335
chartMock.setOption.mockClear();
334336
const {selectNode} = wrapper.vm.composable as ReturnType<typeof useDependencies>;
335337
return {selectNode, chartMock};

0 commit comments

Comments
 (0)