Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!