Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

1 D铆as
13 Hrs
7 Min
12 Seg
Curso de React Testing Library

Curso de React Testing Library

Wilmer Javier Garzon Cabezas

Wilmer Javier Garzon Cabezas

Configuraci贸n del entorno de testing en React

2/20
Resources
Transcript

Why is it vital to implement testing techniques in your project?

The lack of testing can have serious consequences for any company: from economic losses to the deterioration of confidence in the product. Implementing testing techniques in your project not only protects you from these risks, but also guarantees the optimal performance of the software.

Throughout this course, we will work with Platzi Order, an order management application, using various testing techniques that we will explore in depth.

How to clone and prepare your repository for testing?

To start, it is essential to clone the Platzi Order project repository. From the terminal, run the following command:

git clone

Then, access the project folder and make sure to install the necessary dependencies to run the tests. If you use yarn, use the following command:

yarn install

If you prefer npm, then run

npm install

Once everything is installed, you are ready to configure and run the necessary tests.

What dependencies do you need to run tests?

Located inside the project, install the specific dependencies for the test environment with the following command:

yarn add -D

The -D argument indicates that these dependencies will be installed only in the development environment and not in production. The tools we will use are:

  • Testing Library DOM: virtualizes a DOM in a testing environment.

  • Testing Library Jest DOM: provides the necessary matchers.

  • Testing Library React: provides utilities for testing React components.

  • jsdom: adds more test configuration utilities.

  • Vitest: our test runner for this project.

The project will be built on the Vite framework. If you are not familiar with it, check the specific course in the resources section.

How to configure the files to run tests?

With the dependencies installed, it is time to configure the project files. In the root of the project, create a new file called vitest.config.ts and enter the following configuration:

import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { environment: 'jsdom', // Virtualize DOM globals: true, // Enable global matchers setupFiles: ['./src/setuptest.ts'] // Configuration file } });

Don't forget to create the src/setuptest.ts file, as specified in the setup. Make sure the name is accurate to avoid future errors.

How to create and manage testing scripts?

Finally, configure a script to run the tests inside the package.json file, in the scripts section:

"scripts": { "test": "vitest" }

Save the changes, go to the terminal and run:

yarn test

If you see an error stating that no test files were found, don't worry. This is completely normal as you have not yet configured test files.

In the next class we will cover how to create these files and start hands-on testing in your project.

Keep learning and improve your skills! 馃殌

Contributions 5

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Adjunto el comando de instalacion de dependiencias NPM: `npm i @testing-library/dom @testing-library/jest-dom @testing-library/react jsdom vitest -D` YARN `yarn add -D @testing-library/dom @testing-library/jest-dom @testing-library/react jsdom vitest -D`
Justo a tiempo este Curso ajkaj es como si Platzi supiera que es lo que necesito
Yo s茅 que Wilmer dijo que m谩s adelante lo explicaba, pero por si acaso les mata la curiosidad como a mi 馃: **Un matcher** es una funci贸n o herramienta utilizada en pruebas para verificar si un resultado coincide con un valor esperado. En el contexto de Testing Library y Jest, los matchers permiten hacer aserciones sobre el estado de los componentes de React, como verificar si un elemento est谩 presente en el DOM, si tiene un texto espec铆fico o si cumple con ciertas condiciones. Estos matchers facilitan la escritura de pruebas unitarias al proporcionar una forma clara y concisa de validar el comportamiento del c贸digo.
```js https://github.com/platzi/react-testing ```
Veo que Wilmer crea el archivo vitest.config.ts, 驴siempre debe ser .ts? Todo mi proyecto react es .js por eso estaba creando vitest.config.js y (reci茅n estoy entrando al mundo react)