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.
Andrew Clark committed
Dec 19, 2016 at 18:46 UTC
470da6ea77bedcd4123deb2803c7bfe5c339b949
3 files changed
+22
scripts/fiber/tests-passing.txt
+1
@@ -1183,6 +1183,7 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js
1183
* recovers from uncaught reconciler errors
1184
* unmounts components with uncaught errors
1185
* does not interrupt unmounting if detaching a ref throws
1186
+* handles error thrown by host config while working on failed root
1187
1188
src/renderers/shared/fiber/__tests__/ReactIncrementalReflection-test.js
1189
* handles isMounted even when the initial render is deferred
src/renderers/noop/ReactNoop.js
+14
@@ -39,9 +39,14 @@ type TextInstance = {| text: string, id: number |};
39
40
var instanceCounter = 0;
41
42
+var failInBeginPhase = false;
43
+
44
var NoopRenderer = ReactFiberReconciler({
45
46
getRootHostContext() {
47
+ if (failInBeginPhase) {
48
+ throw new Error('Error in host config.');
49
+ }
50
return emptyObject;
51
},
52
@@ -353,6 +358,15 @@ var ReactNoop = {
358
console.log(...bufferedLog);
359
},
360
361
+ simulateErrorInHostConfig(fn : () => void) {
362
+ failInBeginPhase = true;
363
+ try {
364
+ fn();
365
+ } finally {
366
+ failInBeginPhase = false;
367
+ }
368
+ },
369
+
370
};
371
372
module.exports = ReactNoop;
src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js
+7
@@ -917,4 +917,11 @@ describe('ReactIncrementalErrorHandling', () => {
917
// Because there was an error, entire tree should unmount
918
expect(ReactNoop.getChildren()).toEqual([]);
919
});
920
+
921
+ it('handles error thrown by host config while working on failed root', () => {
922
+ ReactNoop.simulateErrorInHostConfig(() => {
923
+ ReactNoop.render(<span />);
924
+ expect(() => ReactNoop.flush()).toThrow('Error in host config.');
925
+ });
926
+ });
927
});