Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

364
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda