@samitouri / QOS-React / commits / 4ba0eb9158

Add a test for recursive context

Dan Abramov committed Nov 14, 2016 at 00:31 UTC 4ba0eb91586c1f9800ced9c73b94568ff906ddb6
1 file changed +31
src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
+31
@@ -1667,4 +1667,35 @@ describe('ReactIncremental', () => {
1667 'ShowBoth {"locale":"en"}',
1668 ]);
1669 });
1670 +
1671 + it('does not leak own context into context provider', () => {
1672 + var ops = [];
1673 + class Recurse extends React.Component {
1674 + static contextTypes = {
1675 + n: React.PropTypes.number,
1676 + };
1677 + static childContextTypes = {
1678 + n: React.PropTypes.number,
1679 + };
1680 + getChildContext() {
1681 + return {n: (this.context.n || 3) - 1};
1682 + }
1683 + render() {
1684 + ops.push('Recurse ' + JSON.stringify(this.context));
1685 + if (this.context.n === 0) {
1686 + return null;
1687 + }
1688 + return <Recurse />;
1689 + }
1690 + }
1691 +
1692 + ReactNoop.render(<Recurse />);
1693 + ReactNoop.flush();
1694 + expect(ops).toEqual([
1695 + 'Recurse {}',
1696 + 'Recurse {"n":2}',
1697 + 'Recurse {"n":1}',
1698 + 'Recurse {"n":0}',
1699 + ]);
1700 + });
1701 });