title: TypeError: getUserInfo is not a function
body: <p>I am using Jest for unit testing my code.</p>
  <p>I have a file userinfo.js</p>
  <pre><code>const getuserdata = async function (req, res, next) {
      let userinfo = await getUserInfo();
      return userinfo;
  }
  
  const getUserInfo = async function (req, res, next) {
      const records = await database.query('select * from users');
      return records;
  }
  module.exports = {
    getuserdata,
    getUserInfo
  }
  </code></pre>
  <p>I want to write test in jest
  I created a file userinfo.test.js for testing.</p>
  <p>code:</p>
  <pre><code>const { getuserdata, getUserInfo } = require('./userinfo');
  
  describe('user data', () =&gt; {
    beforeEach(() =&gt; {
      jest.clearAllMocks();
    });
    test('user info', async () =&gt; {
      jest.mock('Path of file', () =&gt; ({ getUserInfo: jest.fn() }));
      getUserInfo.mockResolvedValue([{id: 1, name: &quot;test&quot;, password: &quot;123456&quot;}]);
      const userdata = await getuserdata();
      expect(userdata).not.toBeUndefined();
    });
  }
  </code></pre>
  <p>I want to test getuserdata but mock getUserInfo.
  When I try to mock by above method it is giving me error that: TypeError: getUserInfo is not a function</p>
  <p>but if I save the getUserInfo in different file then mocking is working properly. can you please suggest me how to fix this issue.</p>