diff --git a/packages/react/src/__tests__/ReactDOMTracing-test.internal.js b/packages/react/src/__tests__/ReactDOMTracing-test.internal.js index 44784911ae6c7..458779baa2a64 100644 --- a/packages/react/src/__tests__/ReactDOMTracing-test.internal.js +++ b/packages/react/src/__tests__/ReactDOMTracing-test.internal.js @@ -538,53 +538,56 @@ describe('ReactDOMTracing', () => { const root = ReactDOM.unstable_createRoot(container); let interaction; - SchedulerTracing.unstable_trace('initialization', 0, () => { - interaction = Array.from(SchedulerTracing.unstable_getCurrent())[0]; - // This render is only CPU bound. Nothing suspends. - root.render(); - }); - expect(Scheduler).toFlushAndYieldThrough(['A']); + TestUtils.act(() => { + SchedulerTracing.unstable_trace('initialization', 0, () => { + interaction = Array.from(SchedulerTracing.unstable_getCurrent())[0]; + // This render is only CPU bound. Nothing suspends. + root.render(); + }); - Scheduler.advanceTime(300); - jest.advanceTimersByTime(300); + expect(Scheduler).toFlushAndYieldThrough(['A']); - expect(Scheduler).toFlushAndYieldThrough(['B']); + Scheduler.advanceTime(300); + jest.advanceTimersByTime(300); - Scheduler.advanceTime(300); - jest.advanceTimersByTime(300); + expect(Scheduler).toFlushAndYieldThrough(['B']); - // Time has now elapsed for so long that we're just going to give up - // rendering the rest of the content. So that we can at least show - // something. - expect(Scheduler).toFlushAndYieldThrough([ - 'Loading C', - 'Commit A', - 'Commit B', - 'Commit Loading C', - ]); + Scheduler.advanceTime(300); + jest.advanceTimersByTime(300); - // Schedule an unrelated low priority update that shouldn't be included - // in the previous interaction. This is meant to ensure that we don't - // rely on the whole tree completing to cover up bugs. - Scheduler.unstable_runWithPriority( - Scheduler.unstable_IdlePriority, - () => root.render(), - ); + // Time has now elapsed for so long that we're just going to give up + // rendering the rest of the content. So that we can at least show + // something. + expect(Scheduler).toFlushAndYieldThrough([ + 'Loading C', + 'Commit A', + 'Commit B', + 'Commit Loading C', + ]); - expect(onInteractionTraced).toHaveBeenCalledTimes(1); - expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction( - interaction, - ); - expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled(); + // Schedule an unrelated low priority update that shouldn't be included + // in the previous interaction. This is meant to ensure that we don't + // rely on the whole tree completing to cover up bugs. + Scheduler.unstable_runWithPriority( + Scheduler.unstable_IdlePriority, + () => root.render(), + ); - // Then we do a second pass to commit the last item. - expect(Scheduler).toFlushAndYieldThrough(['C', 'Commit C']); + expect(onInteractionTraced).toHaveBeenCalledTimes(1); + expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction( + interaction, + ); + expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled(); - expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1); - expect( - onInteractionScheduledWorkCompleted, - ).toHaveBeenLastNotifiedOfInteraction(interaction); + // Then we do a second pass to commit the last item. + expect(Scheduler).toFlushAndYieldThrough(['C', 'Commit C']); + + expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1); + expect( + onInteractionScheduledWorkCompleted, + ).toHaveBeenLastNotifiedOfInteraction(interaction); + }); }); });