title: How can I write useEffect in test code (jest)?
body: <pre><code>// MyCode.tsx
  const MyCode = (props) =&gt; {
      const { useEffect, useRef } = React;
      const { count, setCount } = useState(0)
      const elementRef = useRef(null);
  
      useEffect(() =&gt; {
          setCount(1);
      }, [elementRef]);
  
      const getFunc() {
          return {
              name: 'Mike',
          }
      }
  
      return (
          &lt;React.Fragment&gt;
              &lt;div className=&quot;section&quot; ref={elementRef}&gt;
                  ....
              &lt;/div&gt;
          &lt;/React.Fragment&gt;
      );
  }
  </code></pre>
  <pre><code>// MyCode.test.js
  import * as React from 'react';
  import { render, mount, shallow, shallowWrapper } from 'enzyme';
  import MyCode from '../MyCode';
  
  describe('TEST START', function() {
      let wrapper;
  
      beforeEach(() =&gt; {
          wrapper = shallow(
              &lt;MyCode /&gt;,
          );
      });
  
      it('TEST1', () =&gt; {
          expect(wrapper.find('.section').length).toEqual(1);
      });
  
      it('TEST2', () =&gt; {
          // useEffect(() =&gt; {
          //     setCount(1);
          // }, [elementRef]);
      });
  
      it('TEST3', () =&gt; {
          // const getFunc() {
          //     return {
          //         name: 'Mike',
          //     }
          // }
      });
  });
  
  </code></pre>
  <p>I have some questions.
  It is difficult to write a test code.</p>
  <p>Q1. (TEST2) How can I write useEffect in test code (jest)? I want to get the changed state value.<br />
  Q2. (TEST3) How can I get the return value of the getFunc function?
  I can't do it like this.</p>
  <pre><code>expect(wrapper.getFunc()).toBe({ name: 'Mike' })
  </code></pre>
  <p>help me...</p>