How to test unmounting of functional components when using useEffect for componentWillMount?

I have a functional component where I used useEffect to achieve similar functionality of componentWillUnmount. How to test that using Jest?

My Component:

const myComp = () => {
  useEffect(() => () => {
    console.log('Unmounted');
  }, []);
  return <div>Test</div>;
}


Read more here: https://stackoverflow.com/questions/67384129/how-to-test-unmounting-of-functional-components-when-using-useeffect-for-compone

Content Attribution

This content was originally published by Paveloosha at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: