Skip to content

Commit

Permalink
Add test for updating parent state in cWRP (facebook#8448)
Browse files Browse the repository at this point in the history
Fails in Fiber.
  • Loading branch information
sophiebits authored and laurinenas committed May 28, 2018
1 parent 058b7c4 commit d9d34d0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ src/renderers/shared/shared/__tests__/ReactCompositeComponent-test.js
src/renderers/shared/shared/__tests__/ReactCompositeComponentNestedState-test.js
* should provide up to date values for props

src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js
* should update state when called from child cWRP

src/renderers/shared/shared/__tests__/ReactEmptyComponent-test.js
* should still throw when rendering to undefined
* throws when rendering null at the top level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,44 @@ describe('ReactCompositeComponent-state', () => {
ReactDOM.unmountComponentAtNode(container);
}).not.toThrow();
});

it('should update state when called from child cWRP', function() {
const log = [];
class Parent extends React.Component {
state = {value: 'one'};
render() {
log.push('parent render ' + this.state.value);
return <Child parent={this} value={this.state.value} />;
}
}
let updated = false;
class Child extends React.Component {
componentWillReceiveProps() {
if (updated) {
return;
}
log.push('child componentWillReceiveProps ' + this.props.value);
this.props.parent.setState({value: 'two'});
log.push('child componentWillReceiveProps done ' + this.props.value);
updated = true;
}
render() {
log.push('child render ' + this.props.value);
return <div>{this.props.value}</div>;
}
}
var container = document.createElement('div');
ReactDOM.render(<Parent />, container);
ReactDOM.render(<Parent />, container);
expect(log).toEqual([
'parent render one',
'child render one',
'parent render one',
'child componentWillReceiveProps one',
'child componentWillReceiveProps done one',
'child render one',
'parent render two',
'child render two',
]);
});
});

0 comments on commit d9d34d0

Please sign in to comment.