Skip to content

Commit 1758a0d

Browse files
committed
Fix setState callback error test
1 parent add43be commit 1758a0d

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

scripts/fiber/tests-passing.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ src/renderers/dom/__tests__/ReactDOMProduction-test.js
453453
* should use prod React
454454
* should handle a simple flow
455455
* should call lifecycle methods
456+
* should throw with an error code in production
456457

457458
src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
458459
* should render strings as children
@@ -816,6 +817,7 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js
816817
* continues work on other roots despite caught errors
817818
* continues work on other roots despite uncaught errors
818819
* force unmounts failed subtree before rerendering
820+
* force unmounts failed subtree before rerendering (fragment)
819821
* force unmounts failed root
820822

821823
src/renderers/shared/fiber/__tests__/ReactIncrementalReflection-test.js

src/renderers/shared/fiber/__tests__/ReactIncremental-test.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,30 +1482,26 @@ describe('ReactIncremental', () => {
14821482
ReactNoop.flush();
14831483
ops = [];
14841484

1485-
expect(instance.state.n).toEqual(0);
1486-
1487-
// first good callback
1488-
instance.setState({ n: 1 }, () => ops.push('first good callback'));
1489-
ReactNoop.flush();
1485+
function updater({ n }) {
1486+
return { n: n + 1 };
1487+
}
14901488

1491-
// callback throws
1492-
instance.setState({ n: 2 }, () => {
1493-
throw new Error('Bail');
1489+
instance.setState(updater, () => ops.push('first callback'));
1490+
instance.setState(updater, () => {
1491+
ops.push('second callback');
1492+
throw new Error('callback error');
14941493
});
1494+
instance.setState(updater, () => ops.push('third callback'));
1495+
14951496
expect(() => {
14961497
ReactNoop.flush();
1497-
}).toThrow('Bail');
1498-
1499-
// should set state to 2 even if callback throws up
1500-
expect(instance.state.n).toEqual(2);
1501-
1502-
// another good callback
1503-
instance.setState({ n: 3 }, () => ops.push('second good callback'));
1504-
ReactNoop.flush();
1498+
}).toThrow('callback error');
15051499

1500+
// Should call all callbacks, even though the second one throws
15061501
expect(ops).toEqual([
1507-
'first good callback',
1508-
'second good callback',
1502+
'first callback',
1503+
'second callback',
1504+
'third callback',
15091505
]);
15101506
expect(instance.state.n).toEqual(3);
15111507
});

0 commit comments

Comments
 (0)