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

363
Views
How to mock global Object with Jest in React Native

I have the function:

const someFn = () => {
  const keys = Object.keys(someObj);
  // rest of function
}

In my unit test (with jest), I want to mock the return value of Object.keys:

test('some test', () => {
  jest.mocked(Object.keys).mockReturnValue(['one', 'two']);
  // rest of test
});

But that resulting the following error:

TypeError: jest.mocked(...).mockReturnValue is not a function

Usually It means that I need to first mock the export itself using jest.mock, but with global Object I'm not sure how to do it. I thought maybe:

global.Object = {
  keys: jest.fn(),
}

But that doesn't seem to work at all.

Any idea how to solve this issue? thanks :)

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!