mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add test for state merging when sCU is false
This commit is contained in:
@@ -1410,6 +1410,7 @@ src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js
|
||||
* should call componentDidUpdate of children first
|
||||
* should batch unmounts
|
||||
* should update state when called from child cWRP
|
||||
* should merge state when sCU returns false
|
||||
|
||||
src/renderers/shared/shared/__tests__/ReactEmptyComponent-test.js
|
||||
* should not produce child DOM nodes for null and false
|
||||
|
||||
@@ -385,4 +385,32 @@ describe('ReactCompositeComponent-state', () => {
|
||||
'child render two',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should merge state when sCU returns false', function() {
|
||||
const log = [];
|
||||
class Test extends React.Component {
|
||||
state = {a: 0};
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
log.push(
|
||||
'scu from ' + Object.keys(this.state) +
|
||||
' to ' + Object.keys(nextState)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const container = document.createElement('div');
|
||||
const test = ReactDOM.render(<Test />, container);
|
||||
test.setState({b: 0});
|
||||
expect(log.length).toBe(1);
|
||||
test.setState({c: 0});
|
||||
expect(log.length).toBe(2);
|
||||
expect(log).toEqual([
|
||||
'scu from a to a,b',
|
||||
'scu from a,b to a,b,c',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user