'Stub of Sinon using axios returns undefined

I'm testing using sinon with axios.

// index.js
{
    .. more code
    const result = await axios.get("http://save")
    const sum = result.data.sum
}

And I made a test code by sinon and supertest for e2e test.

// index.test.js
describe('ADMINS GET API, METHOD: GET', () => {
  it('/admins', async () => {
    sandbox
      .stub(axios, 'get')
      .withArgs('http://save')
      .resolves({sum: 12});

    await supertest(app)
      .get('/admins')
      .expect(200)
      .then(async response => {
        expect(response.body.code).toBe(200);
      });
  });
});

But when I test it, it gives me this result.

 // index.js
    {
        .. more code
        const result = await axios.get("http://save")
        const sum = result.data.sum 
        console.log(sum) // undefined
    }

I think I resolved response. But it doesnt' give any response. It just pass axios on supertest.
How can I return correct data in this case?
Thank you for reading it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source