Skip to content

Commit 82e82a7

Browse files
committed
fix async timers
1 parent f62bebe commit 82e82a7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/__tests__/suspense-fake-timers.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ testGateReact19('resolves timer-controlled promise', async () => {
5454
expect(screen.queryByTestId('content')).not.toBeOnTheScreen();
5555
expect(screen.queryByTestId('sibling')).not.toBeOnTheScreen();
5656

57-
await act(async () => await jest.runOnlyPendingTimersAsync());
57+
expect(await screen.findByTestId('content')).toBeOnTheScreen();
5858
expect(screen.getByTestId('content')).toBeOnTheScreen();
5959
expect(screen.getByTestId('sibling')).toBeOnTheScreen();
6060
expect(screen.queryByText('Loading...')).not.toBeOnTheScreen();

src/wait-for.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* globals jest */
2+
import act from './act';
23
import { getConfig } from './config';
34
import { flushMicroTasks } from './flush-micro-tasks';
45
import { copyStackTrace, ErrorWithStack } from './helpers/errors';
@@ -69,7 +70,7 @@ function waitForInternal<T>(
6970
// third party code that's setting up recursive timers so rapidly that
7071
// the user's timer's don't get a chance to resolve. So we'll advance
7172
// by an interval instead. (We have a test for this case).
72-
jest.advanceTimersByTime(interval);
73+
await act(async () => await jest.advanceTimersByTime(interval));
7374

7475
// It's really important that checkExpectation is run *before* we flush
7576
// in-flight promises. To be honest, I'm not sure why, and I can't quite

0 commit comments

Comments
 (0)