title: Mock api call using moxios
body: <p>I am not very familier yet on how to write unit tests via <strong>moxios</strong> and your help would be very much appreciated.</p>
  <p>My request is the following:</p>
  <pre><code>  export const walletRequest = () =&gt; {
      return AWAxiosInstance()
          .get(`${AW_BASE_URL}/account/wallet`)
          .then(response =&gt; {
              if (response) {
                  return formatAccountDetails(response.data);
              }
          })
          .catch(error =&gt; {
              return Promise.reject('Error requesting data from Account &amp; Wallet API', error)
          })
  }  
  </code></pre>
  <p>So basically here in the above function I'm trying to retrieve some data via an axios instance.</p>
  <p>My understanding is that <strong>moxios</strong> is being used to mock the axios instance, but I am not very sure how to write the unit test for the <em>walletRequest()</em> function.</p>
  <p><strong>What I've tried:</strong></p>
  <pre><code>import  moxios  from 'moxios'
  import { walletRequest } from &quot;../balance&quot;;
  import AWAxiosInstance from '../../../../core/aw-axios-instance'
  
  const responseMock = { balance: 100 };
  
  describe(&quot;services/balance2&quot;, () =&gt; {
  
      beforeEach(() =&gt; {
          moxios.install(AWAxiosInstance)
      })
  
      afterEach(() =&gt; {
          moxios.uninstall(AWAxiosInstance)
      })
  
      it(&quot;should call the walletRequest and retrieve data&quot;, () =&gt; {
  
          moxios.wait(() =&gt; {
              const request = moxios.requests.mostRecent()
              request.respondWith({
                  status: 200,
                  response: {
                      responseMock
                  }
              })
          })
          const response = walletRequest().response;
          expect(response).toEqual(responseMock);
      });
  });
  
  </code></pre>
  <p>This doesn't work at this moment as the <em>walletRequest()</em> response is <strong>undefined</strong>.
  What can I do?</p>
  <p>Thank you in advance!</p>