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

218
Visualizações
Running test directly in the browser context

I have recently started to write some tests using jest and I need to run some code in a real browser, so I decided to go with jest-puppeteer, the problem I have with the package is when we use jsdom we have access to the globalThis that has everything a browser has, in other words, the code executed in a context of a pseudo-browser, which is accepted.

// example.test.js

/**
 * @jest-environment jsdom
 */

test('something', () => {
  expect(navigator.vendor).toBeDefined() // Will Pass Successfully
})

but when using jest-puppeteer we don't have a similar effect.

// example.test.js

/**
 * @jest-environment puppeteer
 */

test('something', () => {
  expect(navigator.vendor).toBeDefined() // Will Fail
})

it offers browser, page and context to use, which nullify the reason we use the real browser to test in the first place because we don't have direct access to the browser context, and, if we needed to test some HTMLless code, we should serialize and inject the code which losses all the good features of jest, like coverage and mocking, it doesn't act like what we have with jsdom environment. no matter how much similar jsdom to real browser is, the result of tests might be different in some situations.

about 4 years ago · Juan Pablo Isaza
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