title: useEffect hook not being mocked by jest.spyOn
body: <p>I'm new to React Hooks and what I'm trying to achieve is to test a React component (called CardFooter) that contains a call to useEffect hook that gets triggered a global context variable is modified.</p>
  
  <p>CardFooter.js:</p>
  
  <pre><code>const CardFooter = props =&gt; {
    const [localState, setLocalState] = useState({
      attachmentError: false
    });
    const globalContext = useContext(GlobalContext);
    React.useEffect(()=&gt; {
      setLocalState({
      ...localState,
      attachmentError: globalContext.data.attachmentError
    });
   },[globalContext.data.attachmentError]);
  }
  </code></pre>
  
  <p>CardFooter.test.js:</p>
  
  <pre><code>import Enzyme, { shallow } from 'enzyme';    
  Enzyme.configure({ adapter: new Adapter() });
  describe('&lt;CardFooter  /&gt;', () =&gt; {
    let useEffect;
    const mockUseEffect = () =&gt; {
      useEffect.mockImplementation(f =&gt; f());
    };
  
    useEffect = jest.spyOn(React, "useEffect");
    mockUseEffect(); //
  
    it('should render correctly with no props.', () =&gt; {
    }
  
    const mockUseEffect = () =&gt; {
      useEffect.mockImplementation(f =&gt; f());
    };
  
    useEffect = jest.spyOn(React, "useEffect");
    mockUseEffect();
  
    const wrapper = shallow(&lt;CardFooter /&gt;);
    expect(toJson(wrapper)).toMatchSnapshot();
  
  });
  </code></pre>
  
  <p>the error that I'm getting when running the test is:</p>
  
  <p><a href="https://i.stack.imgur.com/2afAn.png" rel="noreferrer"> TypeError: Cannot read property 'attachmentError' of undefined </a></p>
  
  <p>I tried the approach presented here: <a href="https://medium.com/@pylnata/testing-react-functional-component-using-hooks-useeffect-usedispatch-and-useselector-in-shallow-9cfbc74f62fb" rel="noreferrer">https://medium.com/@pylnata/testing-react-functional-component-using-hooks-useeffect-usedispatch-and-useselector-in-shallow-9cfbc74f62fb</a> . However it seems that shallow does not pick the mocked useEffect implementation. I also tried mocking the useContext and the globalContext.data.attachmentError. Nothing seems to work.</p>