title: How to mock two axios call in same endpoint
body: <p><strong>Example:</strong></p>
  
  <p>In my test I need to mock the two calls to the external apis.
  I can't mock on the second call. With the library 'axios-mock-adapter' and ava I could only mock the first call.</p>
  
  <pre><code>const read = async (req, res) =&gt; {
    try {
      const responseOne = await axios({
        method: 'get',
        url: 'https://api.example.com/search/repositories',
        params: {
          q: 'example',
        },
      })
      const resultOne = responseOne.data
      if (resultOne) {
        let aux = []
        const itemsOne = resultOne.items.slice(0, 10)
        return Promise.all(
          itemsOne.map((p, indexOne) =&gt; {
            aux = [...aux, { id: p.id, name: p.name, arr: [] }]
            return axios({
              headers: { Authorization: `Bearer ${SECRET_KEY}` },
              method: 'get',
              url: 'https://api.example2.com/search/things',
              params: { q: p.name },
            })
              .then(responseTwo =&gt;
                responseTwo.data.array.map(i =&gt; {
                  aux[indexOne].arr.push({
                    id: i.id,
                    created_at: i.created_at,
                    text: i.text,
                  })
                })
              )
              .catch(err =&gt; res.status(500).json(err))
          })
        )
          .then(() =&gt; res.json({ result: aux }))
          .catch(err =&gt; res.status(500).json(err))
      } else res.status(404).json({ message: 'Example not found' })
    } catch (err) {
      res.status(500).json(err)
    }
  }
  </code></pre>
  
  <h3>TEST</h3>
  
  <p>This is my test read.test.js.
  Now I am dealing with the 'ava' and 'axios-mock-adapter' libraries. But the second axios call does not working the mock.</p>
  
  <pre><code>import axios from 'axios'
  import MockAdapter from 'axios-mock-adapter'
  import test from 'ava'
  import read from '../read'
  
  var mock = new MockAdapter(axios)
  
  
  test('GET - /examples', async t =&gt; {
    mock
      .onGet('https://api.example.com/search/repositories, {
        params: {
          q: 'example',
        },
      })
      .reply(200, {
        total_count: 2,
        incomplete_results: false,
        items: [
          {
            id: 555,
            name: 'exampleOne',
          },
          {
            id: 666,
            name: 'exampleTwo',
          },
        ],
      })
      .onGet('https://api.example2.com/search/things', {
        params: { q: 'name' },
        headers: { Authorization: `Bearer ${SECRET_KEY}` },
      })
      .reply(200, {
        statuses: [
          {
            id: 123,
            created_at: 'Thu Feb 27 22:54:02 +0000 2020',
            text: 'Example one.',
          },
          {
            id: 456,
            created_at: 'Wed Feb 26 13:40:20 +0000 2020',
            text: 'Example Two',
          },
        ],
      })
  
    try {
      const res = await read()
      t.assert(res.result[0].id.test(555))
    } catch (err) {
      console.log(`ERROR::: ${err}`)
    }
  </code></pre>