Open Mikilll94 opened 4 years ago
Yep, I would like to add this for sure. I think we need two sections:
There is actually a placeholder for this (last page of the handbook, about Jest mocks).
Are either of these something you are interested in contributing?
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.