Describe the bug
In React, if setState returns null, cDU is not called and so following does not make infinite loop even after cDU is called. (You can check it on this codesandbox by typing text on the input. It prints only one console log at a time.)
export class TestComponent extends Component {
constructor(props) {
super(props);
this.state = {};
}
componentDidUpdate() {
this.setState(() => {
return null;
});
}
render() {
return null;
}
}
However, in enzyme, when I update component, i.e., invoking cDU with above component, will gives me infinite loop like
at withSetStateAllowed (node_modules/enzyme/build/Utils.js:296:21)
at ShallowWrapper.<anonymous> (node_modules/enzyme/build/ShallowWrapper.js:511:42)
at ShallowWrapper.single (node_modules/enzyme/build/ShallowWrapper.js:1735:25)
at ShallowWrapper.setState (node_modules/enzyme/build/ShallowWrapper.js:510:14)
at TestComponent.ShallowWrapper.instance.setState (node_modules/enzyme/build/ShallowWrapper.js:190:35)
at TestComponent.setState [as componentDidUpdate] (TestComponent.js:11:10)
at node_modules/enzyme/build/ShallowWrapper.js:548:28
at withSetStateAllowed (node_modules/enzyme/build/Utils.js:300:3)
at ShallowWrapper.<anonymous> (node_modules/enzyme/build/ShallowWrapper.js:511:42)
at ShallowWrapper.single (node_modules/enzyme/build/ShallowWrapper.js:1735:25)
at ShallowWrapper.setState (node_modules/enzyme/build/ShallowWrapper.js:510:14)
at TestComponent.ShallowWrapper.instance.setState (node_modules/enzyme/build/ShallowWrapper.js:190:35)
at TestComponent.setState [as componentDidUpdate] (TestComponent.js:11:10)
at node_modules/enzyme/build/ShallowWrapper.js:548:28
// and repeat from line 1 to line 7
To Reproduce
git clone https://github.com/Ailrun/enzyme-issue1783
npm i
npm test
Expected behavior
Does not give infinite loop.
Desktop (please complete the following information):
Describe the bug
In React, if
setStatereturnsnull, cDU is not called and so following does not make infinite loop even after cDU is called. (You can check it on this codesandbox by typing text on the input. It prints only one console log at a time.)However, in
enzyme, when I update component, i.e., invoking cDU with above component, will gives me infinite loop likeTo Reproduce
git clone https://github.com/Ailrun/enzyme-issue1783npm inpm testExpected behavior
Does not give infinite loop.
Desktop (please complete the following information):