Skip to content

Commit

Permalink
Add test that we don't restart for initial render
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed May 30, 2019
1 parent a85c1f7 commit 84b320b
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,70 @@ describe('ReactSuspenseWithNoopRenderer', () => {
]);
});

it('does not restart rendering for initial render', async () => {
function Bar(props) {
Scheduler.yieldValue('Bar');
return props.children;
}

function Foo() {
Scheduler.yieldValue('Foo');
return (
<React.Fragment>
<Suspense fallback={<Text text="Loading..." />}>
<Bar>
<AsyncText text="A" ms={100} />
<Text text="B" />
</Bar>
</Suspense>
<Text text="C" />
<Text text="D" />
</React.Fragment>
);
}

ReactNoop.render(<Foo />);
expect(Scheduler).toFlushAndYieldThrough([
'Foo',
'Bar',
// A suspends
'Suspend! [A]',
// But we keep rendering the siblings
'B',
'Loading...',
'C',
// We leave D incomplete.
]);
expect(ReactNoop.getChildren()).toEqual([]);

// Flush the promise completely
Scheduler.advanceTime(100);
await advanceTimers(100);
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);

// Even though the promise has resolved, we should now flush
// and commit the in progress render instead of restarting.
expect(Scheduler).toFlushAndYield(['D']);
expect(ReactNoop.getChildren()).toEqual([
span('Loading...'),
span('C'),
span('D'),
]);

// Await one micro task to attach the retry listeners.
await null;

// Next, we'll flush the complete content.
expect(Scheduler).toFlushAndYield(['Bar', 'A', 'B']);

expect(ReactNoop.getChildren()).toEqual([
span('A'),
span('B'),
span('C'),
span('D'),
]);
});

it('suspends rendering and continues later', async () => {
function Bar(props) {
Scheduler.yieldValue('Bar');
Expand Down

0 comments on commit 84b320b

Please sign in to comment.