mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
New test: retry after error during expired render
This commit is contained in:
+49
@@ -381,6 +381,55 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
});
|
||||
|
||||
it('retries one more time if an error occurs during a render that expires midway through the tree', () => {
|
||||
function Oops() {
|
||||
Scheduler.unstable_yieldValue('Oops');
|
||||
throw new Error('Oops');
|
||||
}
|
||||
|
||||
function Text({text}) {
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<>
|
||||
<Text text="A" />
|
||||
<Text text="B" />
|
||||
<Oops />
|
||||
<Text text="C" />
|
||||
<Text text="D" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
ReactNoop.render(<App />);
|
||||
|
||||
// Render part of the tree
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A', 'B']);
|
||||
|
||||
// Expire the render midway through
|
||||
expect(() => ReactNoop.expire(10000)).toThrow('Oops');
|
||||
|
||||
expect(Scheduler).toHaveYielded([
|
||||
// The render expired, but we shouldn't throw out the partial work.
|
||||
// Finish the current level.
|
||||
'Oops',
|
||||
'C',
|
||||
'D',
|
||||
|
||||
// Since the error occured during a partially concurrent render, we should
|
||||
// retry one more time, synchonrously.
|
||||
'A',
|
||||
'B',
|
||||
'Oops',
|
||||
'C',
|
||||
'D',
|
||||
]);
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
});
|
||||
|
||||
it('calls componentDidCatch multiple times for multiple errors', () => {
|
||||
let id = 0;
|
||||
class BadMount extends React.Component {
|
||||
|
||||
Reference in New Issue
Block a user