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

456
Vistas
ReferenceError: la ventana no está definida, considere usar el entorno de prueba "jsdom" (broma V28)

Quisiera ayuda para resolver este error.

ingrese la descripción de la imagen aquí

Estoy usando Jest V28.0.0.

Así es como se ven el script de prueba y las devDependencies de mi paquete.json

 "scripts":{ ..., "test": "jest --env=node --watchAll --coverage --verbose", }, "devDependencies": { ... "@babel/preset-env": "^7.16.11", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.0", "@types/jest": "^27.4.1", "babel-jest": "^28.0.0", "jest": "^28.0.0", "jest-environment-jsdom": "^28.0.1", "jsdom": "^19.0.0", } }

También tengo un archivo jest.config.js que se ve así

 module.exports = { roots: ['<rootDir>/tests/'], testEnvironment: 'jsdom', testMatch: ['**/?(*.)+(test).js'], transform: { '^.+\\.js?$': 'babel-jest', }, moduleNameMapper: { ... }, }

Mi archivo de prueba real se ve así

 import React from 'react' import { render, cleanup, screen } from '@testing-library/react' import renderer from 'react-test-renderer' import '@testing-library/jest-dom' /** * @jest-environment jsdom */ //components import MyComponent from '../../../../src/website/Components/MyComponent' test('should have the Add recipients text label', () => { const addRecipientsLabel = screen.getByTestId('label-element') expect(true).toBe(true) render(<MyComponent />) expect(addRecipientsLabel).toHaveTextContent('Add Recipients') })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Debe incluir @jest-environment en la parte superior del archivo. Por encima incluso de las importaciones.

https://jestjs.io/docs/configuration#testenvironment-string

P.ej.:

 /** * @jest-environment jsdom */ import React from 'react' //components import MyComponent from '...' test('should have the Add recipients text label', () => { // test })
about 4 years ago · Juan Pablo Isaza 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda