Want to test componentDidUpdate()? I am using a different approach but you can copy the idea. You need to make a change in the props, I used the setProps() function:
1 2 3 4 5 6 7 | describe('componentDidUpdate', () => { it('loads profile', () => { const wrapper = shallow(<Person {...props} />) as any; wrapper.setProps({ person: { uri: "something_different" } }); expect(wrapper.instance().props.onLoadProfile).toBeCalled(); }) }) |
I can see the pink in the coverage tests page is gone in the componentDidUpdate after running the test.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.