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

110
Views
Override Jest global property that's set in setupTests.js for specific tests (CRA, Jest, RTL)

I've set up some global properties inside my setupTests.js for mocking window properties that are needed for my tests.

// setupTests.js

global.CONFIG = {
  property1: "something",
  property2: "something"
};

global.DATA = {
  property1: "something",
  property2: "something"
};

This works fine, but the problem is that I can't seem to override these globals inside specific tests. Ideally, I would like to re-set these properties inside specific tests like this:

// some.test.js

it('should have different global property for this test case', async () => {
  global.DATA = {
    property1: "changed",
    property2: "changed"
  }

  renderWithProviders(<SomeComponent />);
  
  ...
}

Most examples of mocking globals I've found have been about mocking methods, so they don't seem to work for me. (https://stackoverflow.com/a/40460395/13968820) This answer gives me the impression that this should be a working way to do it, but it doesn't work. What can I do to make these globals available to all my tests, and also be able to override them when needed?

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!