Add test for state merging when sCU is false

This commit is contained in:
Ben Alpert
2017-01-12 11:25:11 -08:00
committed by Andrew Clark
parent d17b9a13f8
commit 54ebcbcd18
2 changed files with 29 additions and 0 deletions
+1
View File
@@ -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',
]);
});
});