title: Jest + mockImplementation + Number of calls: 0
body: <p>I am using <code>Jest</code> as testing module. Jest spy function is not called, it says <code>Number of calls: 0</code>.</p>
  
  <p><strong>a.test.js</strong></p>
  
  <pre><code> const request = require('request-promise');
      const moduleA = require('./a');
      test('Update function', async () =&gt; {
      const postSpy = jest.spyOn(request, 'post').mockImplementation((input) =&gt; input);
      await moduleA();
      expect(postSpy).toBeCalledWith({
      method: 'POST',
      uri:"fsdsfd",
      headers: {
       'content-type': 'application/json'
      },
      body: {
        A:A,
        B:B      
      },
      json: true 
  });
      });
  </code></pre>
  
  <p><strong>a.js</strong>     </p>
  
  <pre class="lang-js prettyprint-override"><code>const request = require('request-promise');
  
  module.exports = async () =&gt; {
    var options = {
      method: 'POST',
      uri: 'fsdsfd',
      headers: {
        'content-type': 'application/json',
      },
      body: {
        A: A,
        B: B,
      },
      json: true,
    };
  
    try {
      const selectResult = await request(options);
      return selectResult;
    } catch (err) {
      return err;
    }
  };
  
  </code></pre>
  
  <p>It throws error as <code>expect(jest.fn()).toBeCalledWith(...expected)</code> and <code>Number of calls: 0</code>. I think the mocked function is not called. I searched a lot regarding this but no hope. Any ideas??</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My Guess is that there is no method <code>post</code> in <code>request-promise</code>.</p>
  
  <p><strong>EDIT FOR REQUEST>POST()</strong></p>
  
  <pre><code>    request.post({
        uri: 'fsdsfd',
        headers: {
          'content-type': 'application/json',
        },
        body: {
        A: A,
       B: B,
      },
      json: true,
      }, function(err, resp){
        if(err){
          console.log(err)
        } else {
          console.log(resp);
          return(resp)---------------&gt;
        }
      });
  </code></pre>
  
  <p><strong>ASYNC AWAIT EDIT</strong></p>
  
  <pre><code>const ss = await request.post({
            uri: 'fsdsfd',
            headers: {
              'content-type': 'application/json',
            },
            body: {
            A: A,
           B: B,
          },
          json: true,
          });
  return ss;
  </code></pre>
  
  <p>Here if you use this the arrow (-->) is not getting called so its not assign in test file so I can't check for result values.</p>