Skip to content

Commit

Permalink
Added test case to reproduce issue with child components
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Mar 22, 2016
1 parent b70c6a2 commit 12a1b71
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -28,7 +28,7 @@
"isparta": "^4.0.0",
"isparta-loader": "^2.0.0",
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.2",
"karma-chrome-launcher": "^0.2.3",
"karma-coverage": "^0.5.5",
"karma-coveralls": "^1.1.2",
"karma-mocha": "^0.2.2",
Expand All @@ -42,7 +42,7 @@
"npm-check-updates": "^2.6.1",
"pre-commit": "^1.1.2",
"rimraf": "^2.5.2",
"rollup": "^0.25.4",
"rollup": "^0.25.5",
"rollup-plugin-babel": "2.4.0",
"rollup-plugin-node-resolve": "^1.5.0",
"rollup-plugin-replace": "^1.1.0",
Expand Down
72 changes: 72 additions & 0 deletions src/component/__tests__/components.spec.jsx.js
Expand Up @@ -1353,4 +1353,76 @@ describe('Components (JSX)', () => {
});
});
});

describe('updating child should not cause rendering parent to fail', () => {
it('should render parent correctly after child changes', () => {

let updateParent,
updateChild;

class Parent extends Component {
constructor(props) {
super(props);
this.state = {x: false};

updateParent = () => {
this.setState({x: true});
};
}

render() {
return (
<div>
<p>parent</p>
{!this.state.x? <ChildA /> :<ChildB />}
</div>
);
};
}

class ChildB extends Component {
constructor(props) {
super(props);
};
render() {
return (<div>Y</div>);
};
}

class ChildA extends Component {
constructor(props) {
super(props);
this.state = {z: false};

updateChild = () => {
this.setState({z: true});
}
};

render() {
if (!this.state.z)
return (<div>A</div>);

return (<SubChild />);
};
}

class SubChild extends Component {
constructor(props) {
super(props);
};

render() {
return (<div>B</div>);
};
}

render(<Parent />, container);
expect(container.innerHTML).to.equal('<div><p>parent</p><div>A</div></div>');
updateChild();
expect(container.innerHTML).to.equal('<div><p>parent</p><div>B</div></div>');
updateParent();
expect(container.innerHTML).to.equal('<div><p>parent</p><div>Y</div></div>');
});
})
});

0 comments on commit 12a1b71

Please sign in to comment.