You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have read the whole handbook. It is great, I appreciate it 👍
However, IMO it lacks information about mocking HTTP services. Currently, I noticed that you only describe how to mock the whole axios module which is fine for demonstration purposes. However, in a real-world application, you don't want to do this. Instead, you extract your HTTP communication to separate files most-often called "services", i.e. accountService, taxService, etc. And you mock these services, not whole axios.
This is a better approach because in real-world applications you often have components with multiple HTTP calls, some logic around them, and some error handling.
And the solution like this is not fine:
because you mock all axios "GET" methods with the same response.
IMO, for mocking HTTP services, it would be nice to introduce ES6 class mocks from Jest, but this is just my proposition.
The text was updated successfully, but these errors were encountered:
I have read the whole handbook. It is great, I appreciate it 👍
However, IMO it lacks information about mocking HTTP services. Currently, I noticed that you only describe how to mock the whole
axios
module which is fine for demonstration purposes. However, in a real-world application, you don't want to do this. Instead, you extract your HTTP communication to separate files most-often called "services", i.e. accountService, taxService, etc. And you mock these services, not wholeaxios
.This is a better approach because in real-world applications you often have components with multiple HTTP calls, some logic around them, and some error handling.
And the solution like this is not fine:
because you mock all axios "GET" methods with the same response.
IMO, for mocking HTTP services, it would be nice to introduce ES6 class mocks from Jest, but this is just my proposition.
The text was updated successfully, but these errors were encountered: