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:
Andrew Clark
2016-12-19 18:46:13 -08:00
parent 6c26e98ec2
commit 470da6ea77
3 changed files with 22 additions and 0 deletions
+1
View File
@@ -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
+14
View File
@@ -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.');
});
});
});