title: TypeError: Cannot read property 'get' of undefined while writing unit test with axios
body: <p>I am writing unit tests for a component. My component has a method which is using axios. I want to write unit tests for it. 
  Here is how I have written and I am getting an error. </p>
  
  <pre><code>import axios from "axios";
  jest.mock('axios');
  jest.mock('axios', () =&gt; ({ get: jest.fn(),post: jest.fn(), create: jest.fn() }));
  test("on search it should call get store", () =&gt; {
      axios.get.mockImplementationOnce(() =&gt; Promise.resolve(data));
      const wrapper = shallow(&lt;ComponentA /&gt;);
      const spy = jest.spyOn(wrapper.instance(), "getStores");
      wrapper.setState({
        searchText: "test1"
      });
      wrapper.instance().onSearchClick();
      expect(spy).toHaveBeenCalledWith("test1");
    });
  </code></pre>
  
  <p>here is the method</p>
  
  <pre><code>getStores = term =&gt; {
      const uri = URI("")
        .path("/api/link")
        .addQuery({term: term})
        .toString();
      return axios.get(uri)
        .then(response =&gt; {
          const storeResponse = response.data;
            return storeResponse;
              } catch (error) {}
              this.props.onStoreFetch(stores, false);
            } else {
              this.props.onStoreFetch([], true);
            }
        })
        .catch(error =&gt; {
          this.props.onStoreFetch([], true);
        });
    };
  </code></pre>
  
  <p>Error I am getting is</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'get' of undefined</p>
  </blockquote>