From 12a1b71bb249c9bc4d4c8a116fc23d20d0c9031f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sampo=20Kivist=C3=B6?= Date: Tue, 22 Mar 2016 22:20:20 +0200 Subject: [PATCH] Added test case to reproduce issue with child components --- package.json | 4 +- .../__tests__/components.spec.jsx.js | 72 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7d410b240..f90a68306 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/component/__tests__/components.spec.jsx.js b/src/component/__tests__/components.spec.jsx.js index 86105c61f..2d3f432f8 100644 --- a/src/component/__tests__/components.spec.jsx.js +++ b/src/component/__tests__/components.spec.jsx.js @@ -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 ( +
+

parent

+ {!this.state.x? :} +
+ ); + }; + } + + class ChildB extends Component { + constructor(props) { + super(props); + }; + render() { + return (
Y
); + }; + } + + class ChildA extends Component { + constructor(props) { + super(props); + this.state = {z: false}; + + updateChild = () => { + this.setState({z: true}); + } + }; + + render() { + if (!this.state.z) + return (
A
); + + return (); + }; + } + + class SubChild extends Component { + constructor(props) { + super(props); + }; + + render() { + return (
B
); + }; + } + + render(, container); + expect(container.innerHTML).to.equal('

parent

A
'); + updateChild(); + expect(container.innerHTML).to.equal('

parent

B
'); + updateParent(); + expect(container.innerHTML).to.equal('

parent

Y
'); + }); + }) });