Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

712
Vistas
Use @jest-environment jsdom and @jest-environment node both in the same project [Jest-ReactJS]

We are using "Jest with React Testing Library" for unit testing in our project. In the same project we have some cases those needs "@jest-environment jsdom" and some cases needs @jest-environment node. How can we switch this in a Test Case file.

We have below jest.config.js file:

 /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
    module.exports = {
      preset: 'ts-jest',
      testEnvironment: 'node'
    };

I have tried below approach, but it didn't work in my experience.

/**
 * @jest-environment jsdom
 */

test('use jsdom in this test file', () => {
  const element = document.createElement('div');
  expect(element).not.toBeNull();
});

/**
 * @jest-environment node
 */

test('do not use jsdom in this test file', () => {
  console.log(window); // this will fail as node doesn't have a window object
});
almost 4 years ago · Santiago Trujillo
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda