title: Jest not mocking axios function when the axios request is located in a helper file
body: <p>I have got Jest successfully mocking an axios request for my test function however it only works when axios itself is called from the component that is being tested. When I switch it out to use a helper file (<code>Request.js</code>) that i've created to normalise requests the axios request no longer gets mocked.</p>
  
  <p>In the component that is being tested I have tried putting a simple axios request in like so:</p>
  
  <pre><code>axios.request({
      url: '/test'
  }).then(data =&gt; {
      console.log("Mock data");
      console.log(data);
  })
  </code></pre>
  
  <p>This request works fine and gets mocked by my <code>axios.js</code> file:</p>
  
  <pre><code>module.exports = {
      get: jest.fn(() =&gt; Promise.resolve({
              status: 200,
              payload: {}
          }
      )),
      request: jest.fn(() =&gt; Promise.resolve("Hello World"))
  };
  </code></pre>
  
  <p>When I log out the response to the request it returns "Hello World" which is the expected behaviour and shows it is being correctly mocked.</p>
  
  <p>However, when I switch this out for my helper, the request no longer gets mocked.</p>
  
  <pre><code>Request.get(routes.client.info)
      .then(data =&gt; {
          console.log("DATA");
          console.log(data);
      })
      .catch(err =&gt; console.log(err));
  </code></pre>
  
  <p>The .get method exists on the Request class and looks like so:</p>
  
  <pre><code>static get(url, {params = {}, headers = {}} = {}, returnFullResponse = false) {
      return this.request(url.get || url, {
          method: "GET",
          body: {},
          headers,
          params
      }, returnFullResponse);
  }
  </code></pre>
  
  <p>This method executes the <code>request</code> method which executes the axios request:</p>
  
  <pre><code>static request(url, {method, body = {}, headers = {}, params = {}}, returnFullResponse) {
          return new Promise((resolve, reject) =&gt; {
              axios.request({
                  url,
                  method,
                  responseType: 'json',
                  data: body,
                  headers,
                  params
              })
                  .then(result =&gt; {
                      if(GLOB_VARS &amp;&amp; GLOB_VARS.debugMode) {
                          super.logRequest(url, method, result.data);
                      }
                      result = returnFullResponse ? result : result.data;
                      resolve(result);
                  })
                  .catch(err =&gt; {
                      if(err.response &amp;&amp; err.response.status &amp;&amp; err.response.statusText) {
                          super.logError(url, err.response.status, err.response.statusText);
                          const { status, statusText, data } = err.response;
                          reject({
                              status: status,
                              message: statusText,
                              data: data
                          });
                      }
                      else {
                          reject({
                              status: null,
                              message: err
                          })
                      }
                  })
          });
      }
  </code></pre>
  
  <p>I am unsure why it is not being mocked as in my component file I can successfully mock the <code>request</code> method on Axios however when I make the request using the helper I get <code>undefined</code> as the returned output from axios.</p>
  
  <p>Any ideas?</p>