Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda