• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

669
Vistas
Jest Folder Structure

I'm currently employing the use of Jest in my CRA application. I see that CRA opted for the use of filename.test.js format when writing tests but I find this approach a bit cumbersome on the eyes and brain. I found out that you can write tests in a folder named __tests__ and jest will automatically run the tests in that folder. I like this approach. My question now is, what is the standard when using this setup? Usually, my src folder is set up as such:

src
└── components
    ├── some1ComponentDir
    └── some2ComponentDir  

Do I create a __tests__ folder at each level or do I mock the structure of my src folder inside of my __tests__ folder located inside the src folder?

If you think this is a silly question, please just ignore it and move on. Thanks for any help.

over 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The conventions for Jest, in order of best to worst in my opinion:

  1. src/file.test.js mentioned first in the Getting Started docs, and is great for keeping tests (especially unit) easy to find next to source files
  2. src/__tests__/file.test.js lets you have multiple __tests__ directories so tests are still near original files without cluttering the same directories
  3. __tests__/file.test.js more like older test frameworks that put all the tests in a separate directory; while Jest does support it, it's not as easy to keep tests organized and discoverable

Since you don't want 1, it sounds like 2 is your best option.

over 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda