Hacer test de función con Mock en jest ['ESP','ENG']
Cuando realiza test de programación con javascript por lo general esperamos datos certeros u algún tipo de dato como respuestas, esto es muy útil si el dato no genera ninguna demora en la respuesta u si algo fácil de manejar, pero no es conveniente hacer esto cuando se trata de llamadas a datos de servidores porque la repuestas puede ser bastante grande y esto no es lo que uno busca evaluar con los test, sino el comportamiento de la función.
When you perform programming tests with javascript, we generally expect accurate data or some type of data as responses, this is very useful if the data does not generate any delay in the response or something easy to handle, but it is not convenient to do this when It deals with calls to server data because the response can be quite large and this is not what one seeks to evaluate with the tests, but rather the behavior of the function.
![](https://images.hive.blog/DQmcmJmPuFr1SYTqpsGDxmELW7DGTE2DQNj2Eti87pqHGNb/mock.jpg)
Using “mock” for the tests means that the response that the function must give is the same as that entered in the test, therefore the test only evaluates that the behavior is as expected and also if errors occur, in this way It verifies that the asynchronous function was written well.
![](https://images.hive.blog/DQmbGefDdongCtrcH5mf1qZRCGiqZ4h7o4dtJJetZ5joctr/mock1.jpg)
0
0
0.000
Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!
Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).
You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.