Add test for updating parent state in cWRP (#8448)
Fails in Fiber.
Ben Alpert committed
Nov 28, 2016 at 19:05 UTC
cbe59521af5fae41d1658b8bb049d95d6a23a0aa
2 files changed
+43
scripts/fiber/tests-failing.txt
+3
@@ -93,6 +93,9 @@ src/renderers/shared/shared/__tests__/ReactCompositeComponent-test.js
93
src/renderers/shared/shared/__tests__/ReactCompositeComponentNestedState-test.js
94
* should provide up to date values for props
95
96
+src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js
97
+* should update state when called from child cWRP
98
+
99
src/renderers/shared/shared/__tests__/ReactEmptyComponent-test.js
100
* should still throw when rendering to undefined
101
* throws when rendering null at the top level
src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js
+40
@@ -256,4 +256,44 @@ describe('ReactCompositeComponent-state', () => {
256
ReactDOM.unmountComponentAtNode(container);
257
}).not.toThrow();
258
});
259
+
260
+ it('should update state when called from child cWRP', function() {
261
+ const log = [];
262
+ class Parent extends React.Component {
263
+ state = {value: 'one'};
264
+ render() {
265
+ log.push('parent render ' + this.state.value);
266
+ return <Child parent={this} value={this.state.value} />;
267
+ }
268
+ }
269
+ let updated = false;
270
+ class Child extends React.Component {
271
+ componentWillReceiveProps() {
272
+ if (updated) {
273
+ return;
274
+ }
275
+ log.push('child componentWillReceiveProps ' + this.props.value);
276
+ this.props.parent.setState({value: 'two'});
277
+ log.push('child componentWillReceiveProps done ' + this.props.value);
278
+ updated = true;
279
+ }
280
+ render() {
281
+ log.push('child render ' + this.props.value);
282
+ return <div>{this.props.value}</div>;
283
+ }
284
+ }
285
+ var container = document.createElement('div');
286
+ ReactDOM.render(<Parent />, container);
287
+ ReactDOM.render(<Parent />, container);
288
+ expect(log).toEqual([
289
+ 'parent render one',
290
+ 'child render one',
291
+ 'parent render one',
292
+ 'child componentWillReceiveProps one',
293
+ 'child componentWillReceiveProps done one',
294
+ 'child render one',
295
+ 'parent render two',
296
+ 'child render two',
297
+ ]);
298
+ });
299
});