title: Jest - mocking crypto.Hmac not working with jest.mock()
body: <p>I'm trying to mock the <code>crypto</code> module of nodejs with the jestjs framework.</p>
  <p>Here is the piece of code that I want to mock:
  app.js:</p>
  <pre><code>const hash = crypto
  .createHmac('sha256', API_TOKEN)
  .update(JSON.stringify(body))
  .digest('hex');
  
  if(hash === signature) {
      //verified successfully. Implement next logic
  }
  </code></pre>
  <p>Here, I want the <code>.digest</code> function to give the value contained in the <code>signature</code> variable.</p>
  <p>Following is the mock code:</p>
  <pre><code>jest.mock('crypto', () =&gt; {
    return {
      createHmac: jest.fn(() =&gt; ({
        update: jest.fn(),
        digest: jest.fn(() =&gt; '123')   //here '123' is placeholder for 'signature value
      }))
     };
  });
  </code></pre>
  <p>However, when running the test, the main files throws an error like this:</p>
  <blockquote>
  <p>TypeError: Cannot read property 'update' of undefined</p>
  </blockquote>
  <p>What am I missing here for jest mock?</p>