Skip to content

Commit 54ebcbc

Browse files
sophiebitsacdlite
authored andcommitted
Add test for state merging when sCU is false
1 parent d17b9a1 commit 54ebcbc

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

scripts/fiber/tests-passing.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,7 @@ src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js
14101410
* should call componentDidUpdate of children first
14111411
* should batch unmounts
14121412
* should update state when called from child cWRP
1413+
* should merge state when sCU returns false
14131414

14141415
src/renderers/shared/shared/__tests__/ReactEmptyComponent-test.js
14151416
* should not produce child DOM nodes for null and false

src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,32 @@ describe('ReactCompositeComponent-state', () => {
385385
'child render two',
386386
]);
387387
});
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+
});
388416
});

0 commit comments

Comments
 (0)