With last update there is a way to make axios-mock-adapter to throw an error when unhanded request happen.
const mock = new MockAdapter(axios, { onNoMatch: "throwException" });
So when when I make call I see error:
axios.get("/user/posts");
// Exception message on console:
//
// Could not find mock for:
// {
// "method": "get",
// "url": "http://localhost/user/posts"
// }
Problem
There case when component makes a request to the same API endpoint but with different query param.
For example pagination.
I can setup specific mock for so it will mock only first request but not the second
For example:
With this example I'll get error that looks like this:
Could not find mock for:
{
"method": "get",
"url": "/users"
}
This is quite small amount of information for developer and it may take awhile to understand that the is another call to the same endpoint that mocked but with a bit different params.
Suggested solution
Add more information into the error.
I'd suggest params and request body (POST, PUT, etc requests may have slight difference in body that will lead to same problem)
Domain knowlage
With last update there is a way to make
axios-mock-adapter
to throw an error when unhanded request happen.So when when I make call I see error:
Problem
There case when component makes a request to the same API endpoint but with different query param. For example pagination. I can setup specific mock for so it will mock only first request but not the second For example:
With this example I'll get error that looks like this:
This is quite small amount of information for developer and it may take awhile to understand that the is another call to the same endpoint that mocked but with a bit different params.
Suggested solution
Add more information into the error. I'd suggest
params
andrequest body
(POST, PUT, etc requests may have slight difference in body that will lead to same problem)