Aprovecha el precio especial

Antes:$249

Currency
$209

Paga en 4 cuotas sin intereses

Paga en 4 cuotas sin intereses
Comienza ahora

Termina en:

03d

04h

56m

52s

1

Setup and Teardown [ES][EN]

[EN]
This is a summary of what I learned about Setup and Teardown in Jest, I recommend you to check the official documentation for a deep knowledge
Here I let the link of the Jest documentation --> Click me

Setup

The setup makes reference to settle specific actions before or after running a test. It can be applied to a single test or to several ones. These actions can be for example requesting data from an API or to clean data after the data was used.

Setup for several tests

In this case, Jest gives us the functions beforeEach and afterEach that will apply test by test in the order it is presented.

Setup for a single test

In this case, we employ the functions beforeAll and afterAll, with these at the beginning of the file we make sure the tasks are established and ready to use when needed.

Scoping

These helpers have a scope, which is a block. Globally it applies over describe blocks but inside these, it can’t apply outside the describe blocks.
This is important to know because Jest prioritizes describe blocks when executing and after the tests in order of presentation. So it is recommended to put the tasks we want to apply inside the helpers instead of customizing our own.

Good Advice

If you have a test failing, it is possible to apply a temporary command “test. only” to execute that specific test. It can keep failing, in such cases check out the beforeEach because the state of the test can be altered by it. If the issue persists then use the helper to log data.

Conclusion

Setup helpers offered by Jest allow us to settle specific actions before or after tests or a single test are executed.

I hope I’ve helped you to understand superficially how these setup helpers work. I recommend you to check the official documentation. Greetings !!
[ES]
** Este es un resumen de lo que aprendí sobre la configuración y desmontaje en Jest, te recomiendo que consultes la documentación oficial para conocerlos en profundidad **
Aquí dejo el enlace de la documentación de Jest -> [Click me] (https://jestjs.io/docs/en/setup-teardown)

Preparar

La configuración hace referencia a establecer acciones específicas antes o después de ejecutar una prueba. Se puede aplicar a una sola prueba oa varias. Estas acciones pueden ser, por ejemplo, solicitar datos de una API o limpiar datos después de que se hayan utilizado.

Configuración para varias pruebas

En este caso, Jest nos da las funciones ** beforeEach ** y ** afterEach ** que aplicarán prueba por prueba en el orden en que se presente.

Configuración para una sola prueba

En este caso, empleamos las funciones ** beforeAll ** y ** afterAll **, con estas al inicio del archivo nos aseguramos de que las tareas estén establecidas y listas para usar cuando sea necesario.

Alcance

Estos ayudantes tienen un alcance, que es un bloque. Globalmente, se aplica a los bloques ** describe **, pero dentro de estos, no se puede aplicar fuera de los bloques ** describe **.
Es importante saber esto porque Jest prioriza los bloques de descripción al ejecutar y después de las pruebas en el orden de presentación. Por eso se recomienda poner las tareas que queremos aplicar dentro de los helpers en lugar de personalizar las nuestras.

Buen consejo

Si tiene una prueba que falla, es posible aplicar un comando temporal “solo prueba” para ejecutar esa prueba específica. Puede seguir fallando, en tales casos, consulte el ** beforeEach ** porque el estado de la prueba puede ser alterado por él. Si el problema persiste, utilice el asistente para registrar datos.

Conclusión

Los asistentes de configuración que ofrece Jest nos permiten establecer acciones específicas antes o después de que se ejecuten las pruebas o una sola prueba.

Espero haberte ayudado a comprender superficialmente cómo funcionan estos ayudantes de configuración. Te recomiendo que consultes la documentación oficial. Saludos !!

Escribe tu comentario
+ 2