Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write something about mocking HTTP services #170

Open
Mikilll94 opened this issue Sep 13, 2020 · 1 comment
Open

Write something about mocking HTTP services #170

Mikilll94 opened this issue Sep 13, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@Mikilll94
Copy link

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:
Screenshot 2020-09-13 at 14 18 16

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.

@lmiller1990
Copy link
Owner

Yep, I would like to add this for sure. I think we need two sections:

  1. add an entire section about jest mocks
  2. add something small about mocking axios (or services, or whatever) on the page that talks about mocking axios. It could link to (1)

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?

@lmiller1990 lmiller1990 added the enhancement New feature or request label Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants