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

161
Vistas
How to wait to execute await statement jest

I have a component that asynchronously loads configuration from external config server and awaits for the response, i have mocked the response object with global.fetch, however my console statement is not reached, test skip executing statements after await call. Below the line after await statement is not logged. How to make jest to wait the promise is resolved?

StyleWrapper.tsx

const StyleWrapper: FC = (props) => {
  let async arrangeTiles = async() => {
    const styleConf = await StyleWrapperHelper.getStyleConfig();
    console.log(styleConf.defaultStyleName); // This line not executed during test!!!
  };
  return (
    <Context.Provider value={{ arrangeTiles }}>
      <div id="cnplStyleWrapper">{props.children}</div>
    </Context.Provider>
  );
};

StyleWrapper.test.tsx

test('Test Load style configuration', () => {

   global.fetch = jest.fn(() =>
   Promise.resolve({
            json: () => Promise.resolve({"maxNumberOfTiles":20, "defaultStyleName": "CNPLCore"}),
        })
      ) as jest.Mock;

   const styleWrapper = mount(<StyleWrapper />);
   styleWrapper.update();
      
   expect(container.html()).toMatchSnapshot();
});
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