ctimmerm / axios-mock-adapter

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

Data in mock replaces whole axios response #325

Closed kosuha606 closed 2 years ago

kosuha606 commented 2 years ago

Hello, in documentation we have such example

mock.onGet("/users").reply(200, {
  users: [{ id: 1, name: "John Smith" }],
});

But for me it looks like data object from example replaces whole axios response object. I can't read users from axiosResponse.data

my axios code:

axios.get('/users').then((response) => console.log(response.data)) 

It works only if mock will be as follow:

mock.onGet("/users").reply(200, {
  data: {
    users: [{ id: 1, name: "John Smith" }],
  }
});

Is this ok? Is it mistake in documentation or it is my misunderstanding?

kosuha606 commented 2 years ago

Sorry, It was my misunderstanding.

In axios interseptors was code what changes response to response.data