title: How to Test React Hooks useEffect, useCallBack
body: <p>I'm trying to write unit test cases using Jest, Enzyme for useEffect, and useCallback for React hooks but I'm unable to succeed. Can you someone help me to write a test case for the below code.</p>
  <p>ModalComponent.jsx</p>
  <pre><code>  const ModalComponent = ({ closeModal }) =&gt; {
       const handleModal = useCallback((event) =&gt; {
          if (event.keyCode === 27) {
            closeModal(false);
          }
       }
       useEffect(() =&gt; {
          document.addEventListener('keydown', handleModal);
          return () =&gt; document.removeEventListener('keydown', handleModal);
       }, []);
  
       return (
          &lt;Modal&gt;
            &lt;Header onClose={closeModal} /&gt;
            &lt;Body /&gt;
            &lt;Footer /&gt;
          &lt;/Modal&gt;
       );
    }
  </code></pre>
  <p>ModalComponent.spec.jsx</p>
  <pre><code>  describe('Modal Component', () =&gt; {
       let props;
       beforeEach(() =&gt; {
         props = {
           closeModal: jest.fn(),
         };
       };
  
       it('should handle useEffect', () =&gt; {
          jest.spyOn(React, 'useEffect').mockImplementation(f =&gt; f());
          document.addEventListener('keydown', handleModal); 
          document.removeEventListener('keydown', handleModal);
          const component = shallow(&lt;ModalComponent /&gt;);
       });
    });
  </code></pre>
  <p>It is unable to cover these lines <code>document.addEventListener('keydown', handleModal);</code>,<code>document.removeEventListener('keydown', handleModal);</code>, <code>if(event.keyCode === 27)</code>, <code>closeModal(false)</code>. How can I cover the test cases?</p>