Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

462
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda