title: Mock a function from another file - Jest
body: <p>I am writing Unit test cases for my application. There is one function which is written in Utils section and Used in all files. I wanted to mock this Utils function whenever I need but I am unable to do so.</p>
  
  <p>Here is my code setup:</p>
  
  <p>Utils.js</p>
  
  <pre><code>&gt; const getData = (name) =&gt; "Hello !!! " + name;
  &gt; 
  &gt; const getContact = ()=&gt; return Contacts.mobile;
  &gt; 
  &gt; export {
  &gt;     getData,
  &gt;     getContact }
  </code></pre>
  
  <p>Login.js (Which uses Utils.js)</p>
  
  <pre><code>    const welcomeMessage = (name) =&gt; {
  
      return getData(name);
      }
  </code></pre>
  
  <p>My Test file (Login.spec.js)</p>
  
  <pre><code>import { getData } from '../../src/utils';
  
  
  jest.mock('getData', () =&gt; jest.fn())
  
  
  describe('User actions', () =&gt; {
  
      it('should get username', () =&gt; {
          const value = 'Hello !!! Jest';
          expect(welcomeMessage('Jest')).toEqual(value);
      });
  
  });
  </code></pre>
  
  <p>When I run my test case then I am getting this error:</p>
  
  <pre><code> Cannot find module 'getData' from 'Login.spec.js'
  </code></pre>
  
  <p>I tried to find the solution on official Jest Documentation and on SO as well but couldn't found anything. I am unable to fix this error and mock this function.</p>