@samitouri / QOS-React-2 / commits / 54ebcbcd18

Add test for state merging when sCU is false

Ben Alpert committed Jan 12, 2017 at 11:25 UTC 54ebcbcd183b059ca2e46d183e5c0da8870a0107
2 files changed +29
scripts/fiber/tests-passing.txt
+1
@@ -1410,6 +1410,7 @@ src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js
1410 * should call componentDidUpdate of children first
1411 * should batch unmounts
1412 * should update state when called from child cWRP
1413 +* should merge state when sCU returns false
1414
1415 src/renderers/shared/shared/__tests__/ReactEmptyComponent-test.js
1416 * should not produce child DOM nodes for null and false
src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js
+28
@@ -385,4 +385,32 @@ describe('ReactCompositeComponent-state', () => {
385 'child render two',
386 ]);
387 });
388 +
389 + it('should merge state when sCU returns false', function() {
390 + const log = [];
391 + class Test extends React.Component {
392 + state = {a: 0};
393 + render() {
394 + return null;
395 + }
396 + shouldComponentUpdate(nextProps, nextState) {
397 + log.push(
398 + 'scu from ' + Object.keys(this.state) +
399 + ' to ' + Object.keys(nextState)
400 + );
401 + return false;
402 + }
403 + }
404 +
405 + const container = document.createElement('div');
406 + const test = ReactDOM.render(<Test />, container);
407 + test.setState({b: 0});
408 + expect(log.length).toBe(1);
409 + test.setState({c: 0});
410 + expect(log.length).toBe(2);
411 + expect(log).toEqual([
412 + 'scu from a to a,b',
413 + 'scu from a,b to a,b,c',
414 + ]);
415 + });
416 });