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

218
Visualizações
Getting error on await act() JEST. Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout

I am new to unit testing and jest, and was stuck at a scenario where the react's state are being set asynchronously after API call is resolved or rejected. I found some answers in which they've mentioned to use waitFor or await act(async()=>{}). Whenever I'm trying to await with act or even async act, I'm getting this error and the tests are failing. I've tried to replicate a similar scenario below. If these ways of handling async updates to component are not correct, then what could be the other solutions. I'm using react hooks to set the state after api resolves or rejects.

React and react-dom version : 16.8

test('new ', async () => {
  await act(() => {
    console.log('test');
  });
  expect('temp').toBe('temp');
});
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