title: Sinon unit testing for asynchronous call
body: <p>I want to test a function that loads some data and check whether the list is empty or not.</p>
  <p>I get some <code>errors</code> like below</p>
  <blockquote>
  <p>Network fetch error</p>
  <p>.map is not a function</p>
  <p>stub is called 0 times</p>
  </blockquote>
  <p>I am new to javascript any help will be appreciated.</p>
  <pre><code>loadmythings = async () =&gt; {
    const list = await getmythings();
    const finalvalues = []
    list.map(item =&gt; values.push({ value: item.name }))
    return value
  }
  </code></pre>
  <p><code>api.js</code></p>
  <pre><code>export function getmythings(arg1, arg2) {
    url = &quot;/someurl&quot;
    returns fetch(url).then(response =&gt; response.json())
      .then(json =&gt; json)
      .catch(error =&gt; error)
  }
  </code></pre>
  <p>the code that I tried is :
  import * as api1 from ../api/..api.js</p>
  <pre><code>describe('testing', () =&gt; {
    it('check list', async () =&gt; {
      const apptest = new loadmythings_1()
      const mockdata = [{ name: &quot;my_name&quot; }]
      const stub = sinon.stub(api1, 'getmythings').returns(mockdata);
      const finalList = await apptest.loadmythings();
      sinon.assert.calledOnce(stub);
      expect(finalList).to.equal(mockdata)
    });
  });
  </code></pre>