title: How to mock return value of async function?
body: <p>I'm trying to test function which uses 'easy-soap-request' library.
  I want to mock results returned by 'soapRequest' function. </p>
  
  <p>I've tried <a href="https://stackoverflow.com/questions/42135426/how-to-mock-a-function-inside-another-function-which-i-am-testing-using-sinon">this</a> but it didn't worked, I keep getting data from external API.</p>
  
  <p>client.js</p>
  
  <pre><code>const soapRequest = require('easy-soap-request');
  
  async function get_data(){
      var response = await soapRequest(url, auth_headers) //this is what I want to mock
      var result;
      result = some_parsing_function(response); //this is what I want test
      return result;
  }
  </code></pre>
  
  <p>test.js</p>
  
  <pre><code>const client = require('../../client');
  
  describe('get_data tests', () =&gt;{
      it('should test sth', function (done) {
  
          var stubed = stub(client, 'soapRequest').returns('dummy value');
  
          client.get_data().then((result) =&gt; {
              //assertions
              console.log(result) //result still has value from external service
              done();
          });
  
      })
  });
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>So I've tried using sinon.fake() as suggested by one of the answers.</p>
  
  <pre><code>const client = require('../../client');
  
  describe('get_data tests', () =&gt;{
      it('should test sth', function (done) {
  
          var fake_soap = fake(async () =&gt; {
              return 12345;
          });
  
          replace(cilent, 'soapRequest', fake_soap);
  
          client.soapRequest().then((res) =&gt; {
              console.log(res); // 12345
          })
  
          client.get_data().then((result) =&gt; {
              //assertions
              console.log(result) //still original value from external service
              done();
          });
  
      })
  });
  </code></pre>