mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add test for errors in host config while working on failed root
Test for a bug fixed in the previous commit that was causing an infinite loop.
This commit is contained in:
@@ -1183,6 +1183,7 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js
|
||||
* recovers from uncaught reconciler errors
|
||||
* unmounts components with uncaught errors
|
||||
* does not interrupt unmounting if detaching a ref throws
|
||||
* handles error thrown by host config while working on failed root
|
||||
|
||||
src/renderers/shared/fiber/__tests__/ReactIncrementalReflection-test.js
|
||||
* handles isMounted even when the initial render is deferred
|
||||
|
||||
@@ -39,9 +39,14 @@ type TextInstance = {| text: string, id: number |};
|
||||
|
||||
var instanceCounter = 0;
|
||||
|
||||
var failInBeginPhase = false;
|
||||
|
||||
var NoopRenderer = ReactFiberReconciler({
|
||||
|
||||
getRootHostContext() {
|
||||
if (failInBeginPhase) {
|
||||
throw new Error('Error in host config.');
|
||||
}
|
||||
return emptyObject;
|
||||
},
|
||||
|
||||
@@ -353,6 +358,15 @@ var ReactNoop = {
|
||||
console.log(...bufferedLog);
|
||||
},
|
||||
|
||||
simulateErrorInHostConfig(fn : () => void) {
|
||||
failInBeginPhase = true;
|
||||
try {
|
||||
fn();
|
||||
} finally {
|
||||
failInBeginPhase = false;
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
module.exports = ReactNoop;
|
||||
|
||||
@@ -917,4 +917,11 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
// Because there was an error, entire tree should unmount
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
});
|
||||
|
||||
it('handles error thrown by host config while working on failed root', () => {
|
||||
ReactNoop.simulateErrorInHostConfig(() => {
|
||||
ReactNoop.render(<span />);
|
||||
expect(() => ReactNoop.flush()).toThrow('Error in host config.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user