Add a failing test for context when reusing work
We mistakingly forget to push the context if the parent is being reused but the child is not.
Dan Abramov committed
Nov 14, 2016 at 00:32 UTC
c22b7a001cc7e1a0f75e4f4826782bce1949ffee
1 file changed
+58
src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
+58
@@ -1698,4 +1698,62 @@ describe('ReactIncremental', () => {
1698
'Recurse {"n":0}',
1699
]);
1700
});
1701
+
1702
+ it('provides context when reusing work', () => {
1703
+ var ops = [];
1704
+
1705
+ class Intl extends React.Component {
1706
+ static childContextTypes = {
1707
+ locale: React.PropTypes.string,
1708
+ };
1709
+ getChildContext() {
1710
+ return {
1711
+ locale: this.props.locale,
1712
+ };
1713
+ }
1714
+ render() {
1715
+ ops.push('Intl ' + JSON.stringify(this.context));
1716
+ return this.props.children;
1717
+ }
1718
+ }
1719
+
1720
+ class ShowLocale extends React.Component {
1721
+ static contextTypes = {
1722
+ locale: React.PropTypes.string,
1723
+ };
1724
+
1725
+ render() {
1726
+ ops.push('ShowLocale ' + JSON.stringify(this.context));
1727
+ return this.context.locale;
1728
+ }
1729
+ }
1730
+
1731
+ ops.length = 0;
1732
+ ReactNoop.render(
1733
+ <Intl locale="fr">
1734
+ <ShowLocale />
1735
+ <div hidden="true">
1736
+ <ShowLocale />
1737
+ <Intl locale="ru">
1738
+ <ShowLocale />
1739
+ </Intl>
1740
+ </div>
1741
+ <ShowLocale />
1742
+ </Intl>
1743
+ );
1744
+ ReactNoop.flushDeferredPri(40);
1745
+ expect(ops).toEqual([
1746
+ 'Intl null',
1747
+ 'ShowLocale {"locale":"fr"}',
1748
+ 'ShowLocale {"locale":"fr"}',
1749
+ ]);
1750
+
1751
+ ops.length = 0;
1752
+ ReactNoop.flush();
1753
+ expect(ops).toEqual([
1754
+ 'ShowLocale {"locale":"fr"}',
1755
+ 'Intl null',
1756
+ 'ShowLocale {"locale":"ru"}',
1757
+ ]);
1758
+ });
1759
});