title: Nodejs: Testing with sinon and async/await
body: <p>Having trouble getting this test to run using sinon and async/await. Here is an example of what I'm doing:</p>
  
  <pre><code>// in file funcs
  async function funcA(id) {
      let url = getRoute53() + id
      return await funcB(url);
  }
  
  async function funcB(url) {
      // empty function
  }
  </code></pre>
  
  <p>And the test:</p>
  
  <pre><code>let funcs = require('./funcs');
  
  ...
  
  // describe
  let stubRoute53 = null;
  let stubFuncB = null;
  let route53 = 'https://sample-route53.com/' 
  let id = '1234'
  let url = route53 + id;
  
  beforeEach(() =&gt; {
      stubRoute53 = sinon.stub(funcs, 'getRoute53').returns(route53);
      stubFuncB = sinon.stub(funcs, 'funcB').resolves('Not interested in the output');
  })
  
  afterEach(() =&gt; {
      stubRoute53.restore();
      stubFuncB.restore();
  })
  
  it ('Should create a valid url and test to see if funcB was called with the correct args', async () =&gt; {
      await funcs.funcA(id);
      sinon.assert.calledWith(stubFuncB, url)
  })
  </code></pre>
  
  <p>Via <code>console.log</code> I've verified that <code>funcA</code> is producing the correct URL, however, I'm getting the error <code>AssertError: expected funcB to be called with arguments</code>. When I try calling <code>stubFuncB.getCall(0).args</code> it prints out null. So maybe it is my lack of understanding of async/await, but I cannot figure out why the url is not being passed to that function call.</p>
  
  <p>Thanks</p>