@@ -575,7 +575,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { |
575 | 575 | <Suspense fallback="Loading..."> |
576 | 576 | <Text text="Sibling" /> |
577 | 577 | {shouldSuspend ? ( |
578 | | - <AsyncText ms={10000} text={'Step ' + step} /> |
| 578 | + <AsyncText text={'Step ' + step} /> |
579 | 579 | ) : ( |
580 | 580 | <Text text={'Step ' + step} /> |
581 | 581 | )} |
@@ -2595,7 +2595,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { |
2595 | 2595 | } |
2596 | 2596 | return ( |
2597 | 2597 | <Suspense fallback={<Text text="Loading..." />}> |
2598 | | - <AsyncText text={page} ms={5000} /> |
| 2598 | + <AsyncText text={page} /> |
2599 | 2599 | </Suspense> |
2600 | 2600 | ); |
2601 | 2601 | } |
@@ -2616,8 +2616,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { |
2616 | 2616 | }); |
2617 | 2617 |
|
2618 | 2618 | // Later we load the data. |
2619 | | - Scheduler.unstable_advanceTime(5000); |
2620 | | - await advanceTimers(5000); |
| 2619 | + await resolveText('A'); |
2621 | 2620 | expect(Scheduler).toHaveYielded(['Promise resolved [A]']); |
2622 | 2621 | expect(Scheduler).toFlushAndYield(['A']); |
2623 | 2622 | expect(ReactNoop.getChildren()).toEqual([span('A')]); |
@@ -2635,8 +2634,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { |
2635 | 2634 | }); |
2636 | 2635 |
|
2637 | 2636 | // Later we load the data. |
2638 | | - Scheduler.unstable_advanceTime(3000); |
2639 | | - await advanceTimers(3000); |
| 2637 | + await resolveText('B'); |
2640 | 2638 | expect(Scheduler).toHaveYielded(['Promise resolved [B]']); |
2641 | 2639 | expect(Scheduler).toFlushAndYield(['B']); |
2642 | 2640 | expect(ReactNoop.getChildren()).toEqual([span('B')]); |
@@ -2754,12 +2752,14 @@ describe('ReactSuspenseWithNoopRenderer', () => { |
2754 | 2752 | ); |
2755 | 2753 | }); |
2756 | 2754 |
|
| 2755 | + // TODO: This test is specifically about avoided commits that suspend for a |
| 2756 | + // JND. We may remove this behavior. |
2757 | 2757 | it("suspended commit remains suspended even if there's another update at same expiration", async () => { |
2758 | 2758 | // Regression test |
2759 | 2759 | function App({text}) { |
2760 | 2760 | return ( |
2761 | 2761 | <Suspense fallback="Loading..."> |
2762 | | - <AsyncText ms={2000} text={text} /> |
| 2762 | + <AsyncText text={text} /> |
2763 | 2763 | </Suspense> |
2764 | 2764 | ); |
2765 | 2765 | } |
@@ -2768,34 +2768,28 @@ describe('ReactSuspenseWithNoopRenderer', () => { |
2768 | 2768 | await ReactNoop.act(async () => { |
2769 | 2769 | root.render(<App text="Initial" />); |
2770 | 2770 | }); |
| 2771 | + expect(Scheduler).toHaveYielded(['Suspend! [Initial]']); |
2771 | 2772 |
|
2772 | 2773 | // Resolve initial render |
2773 | 2774 | await ReactNoop.act(async () => { |
2774 | | - Scheduler.unstable_advanceTime(2000); |
2775 | | - await advanceTimers(2000); |
| 2775 | + await resolveText('Initial'); |
2776 | 2776 | }); |
2777 | | - expect(Scheduler).toHaveYielded([ |
2778 | | - 'Suspend! [Initial]', |
2779 | | - 'Promise resolved [Initial]', |
2780 | | - 'Initial', |
2781 | | - ]); |
| 2777 | + expect(Scheduler).toHaveYielded(['Promise resolved [Initial]', 'Initial']); |
2782 | 2778 | expect(root).toMatchRenderedOutput(<span prop="Initial" />); |
2783 | 2779 |
|
2784 | | - // Update. Since showing a fallback would hide content that's already |
2785 | | - // visible, it should suspend for a bit without committing. |
2786 | 2780 | await ReactNoop.act(async () => { |
| 2781 | + // Update. Since showing a fallback would hide content that's already |
| 2782 | + // visible, it should suspend for a JND without committing. |
2787 | 2783 | root.render(<App text="First update" />); |
2788 | | - |
2789 | 2784 | expect(Scheduler).toFlushAndYield(['Suspend! [First update]']); |
| 2785 | + |
2790 | 2786 | // Should not display a fallback |
2791 | 2787 | expect(root).toMatchRenderedOutput(<span prop="Initial" />); |
2792 | | - }); |
2793 | 2788 |
|
2794 | | - // Update again. This should also suspend for a bit. |
2795 | | - await ReactNoop.act(async () => { |
| 2789 | + // Update again. This should also suspend for a JND. |
2796 | 2790 | root.render(<App text="Second update" />); |
2797 | | - |
2798 | 2791 | expect(Scheduler).toFlushAndYield(['Suspend! [Second update]']); |
| 2792 | + |
2799 | 2793 | // Should not display a fallback |
2800 | 2794 | expect(root).toMatchRenderedOutput(<span prop="Initial" />); |
2801 | 2795 | }); |
@@ -3989,9 +3983,6 @@ describe('ReactSuspenseWithNoopRenderer', () => { |
3989 | 3983 | await ReactNoop.act(async () => { |
3990 | 3984 | root.render(<App show={true} />); |
3991 | 3985 | }); |
3992 | | - // TODO: `act` should have already flushed the placeholder, so this |
3993 | | - // runAllTimers call should be unnecessary. |
3994 | | - jest.runAllTimers(); |
3995 | 3986 | expect(Scheduler).toHaveYielded(['Suspend! [Async]', 'Loading...']); |
3996 | 3987 | expect(root).toMatchRenderedOutput( |
3997 | 3988 | <> |
|