title: How to test Axios reject condition using Jest
body: <p>I wrote a unit test for some Axios calls in my component. I verified the success path, where the call resolves successfully, but I am not able to verify the failure path, where the call rejects. How do I use mocks to verify this?</p>
  
  <p>Here's a snippet of my <code>FetchImage.vue</code> component:</p>
  
  <pre class="lang-js prettyprint-override"><code>methods: {
    preparedFetch() {
      axios.get(this.imageurl).then(result =&gt; {
        this.imageInformation.title = result.data.title;
        this.imageInformation.copyright = result.data.copyright;
        this.imageInformation.detailExplanation = result.data.explanation;
        this.imageInformation.date = result.data.date;
        this.imageInformation.urlinfo = result.data.url;
        this.resultArrived = true;
        this.$emit('imagefetched',this.imageInformation);
      })
      .catch( error =&gt; {
        this.errorMessage = "Information not found";
        this.resultArrived = true;
      });
    }
  }
  </code></pre>
  
  <p>And my test for when the call rejects (for an invalid URL):</p>
  
  <pre class="lang-js prettyprint-override"><code>describe('Invalid response',async () =&gt; {
    beforeEach(() =&gt; {
      axios.get.mockClear();
      axios.get.mockReturnValue(Promise.reject({}));
    });
    it('Invalid URL verfication', async () =&gt; {
      // Given
      const result = {
          errorMessage : "Information not found",
          resultArrived : true,
          fetchStatus : true
      };
      // Fetch the error result
      axios.get.mockReturnValue(Promise.resolve(result));
      const fetchwrapper = mount(FetchImage);
      fetchwrapper.vm.imageurl = "https://invalid.request.gov";
      fetchwrapper.vm.preparedFetch();
      await fetchwrapper.vm.$nextTick();
      // Validate the result
      expect(axios.get).not.toHaveBeenCalledWith('https://api.nasa.gov/planetary/apod?api_key=vME6LAMD7IhEiy7rDmjfIaG6MhiKbu1MNIqxtqd1');
      expect(axios.get).toHaveBeenCalledWith("https://invalid.request.gov");
      expect(axios.get).toHaveBeenCalledTimes(1);
      expect(fetchwrapper.vm.errorMessage.length).not.toEqual(0);
      expect(fetchwrapper.vm.errorMessage).toBe("Information not found");
    });
  });
  </code></pre>