React unit test how to change props to detect componentDidUpdate hooks

A React component, for which we are going to write a unit test, using Jest with react-dom/test-utils, so how to change the props to cover componentDidUpdate and componentWillRecieveProps ?

Mar.25,2021

https://discuss.reactjs.org/t.

var view = TestUtils.renderIntoDocument(<TestComponent value="abc" />);

// previously
view.setProps({ value: 'newValue' });
expect(view.state.someVal).to.be(someValue);

// now
ReactDOM.render(<TestComponent value="newValue" />, ReactDOM.findDOMNode(view).parentNode);
expect(view.state.someVal).to.be(someNewValue);
Menu