ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.46k stars 245 forks source link

Mocking request(object) #91

Open TrueWill opened 6 years ago

TrueWill commented 6 years ago

I'm trying to mock this code:

axiosInstance
  .request(originalRequest)
  .then(...);

Where originalRequest is an object like:

{
  headers: { },
  baseURL: 'http://localhost:3000/test',
  method: 'get',
  url: '/test'
}

This is supported by axios but results in "Network Error" (that is, passed through to axios) when mocked.

TrueWill commented 6 years ago

One workaround is to use and mock the default axios instance; then calls to request can be mocked.