Skip to content

Commit

Permalink
Add failing test for stuck Suspense fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and acdlite committed Nov 4, 2018
1 parent f444c28 commit 180f0dd
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,5 +690,33 @@ describe('ReactSuspense', () => {
);
expect(mounts).toBe(1);
});

it('does not get stuck with fallback in concurrent mode for a large delay', () => {
function App(props) {
return (
<Suspense maxDuration={10} fallback={<Text text="Loading..." />}>
<AsyncText ms={1000} text="Child 1" />
<AsyncText ms={7000} text="Child 2" />
</Suspense>
);
}

const root = ReactTestRenderer.create(<App />, {
unstable_isConcurrent: true,
});

expect(root).toFlushAndYield([
'Suspend! [Child 1]',
'Suspend! [Child 2]',
'Loading...',
]);
jest.advanceTimersByTime(1000);
expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Child 1]']);
expect(root).toFlushAndYield(['Child 1', 'Suspend! [Child 2]']);
jest.advanceTimersByTime(6000);
expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Child 2]']);
expect(root).toFlushAndYield(['Child 1', 'Child 2']);
expect(root).toMatchRenderedOutput(['Child 1', 'Child 2'].join(''));
});
});
});

0 comments on commit 180f0dd

Please sign in to comment.