Skip to content

Commit 0abbe04

Browse files
committed
[code-infra] make sure to clean up fake timers
1 parent aa8cf28 commit 0abbe04

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

packages-internal/test-utils/src/createRenderer.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ function createClock(
221221
vi.setSystemTime(config);
222222
}
223223
});
224+
225+
afterEach(async () => {
226+
if (vi.isFakeTimers()) {
227+
await rtlAct(async () => {
228+
vi.runOnlyPendingTimers();
229+
});
230+
vi.useRealTimers();
231+
}
232+
});
224233
} else {
225234
beforeEach(() => {
226235
if (config) {
@@ -229,15 +238,6 @@ function createClock(
229238
});
230239
}
231240

232-
afterEach(async () => {
233-
if (vi.isFakeTimers()) {
234-
await rtlAct(async () => {
235-
vi.runOnlyPendingTimers();
236-
});
237-
vi.useRealTimers();
238-
}
239-
});
240-
241241
return {
242242
withFakeTimers: () => {
243243
if (vi.isFakeTimers()) {
@@ -266,6 +266,15 @@ function createClock(
266266
vi.setSystemTime(config);
267267
}
268268
});
269+
270+
afterEach(async () => {
271+
if (vi.isFakeTimers()) {
272+
await rtlAct(async () => {
273+
vi.runOnlyPendingTimers();
274+
});
275+
vi.useRealTimers();
276+
}
277+
});
269278
},
270279
runToLast: () => {
271280
rtlAct(() => {

0 commit comments

Comments
 (0)