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

251
Visualizações
Test with react-aria useButton gives me the famous "act" warning

I'm using react-aria and react testing-library. In my Button component, i'm using react-aria's useButton and I use onPress prop to pass the function to call once click. In the unit test, I just try to click it in order to trigger a simple jest.fn() function, and all I do after that is check if function have been called.

const handleOnClick = jest.fn();
render(<Button onPress={handleOnClick}>test me</Button>);

userEvent.click(screen.getByRole('button'));
expect(handleOnClick).toHaveBeenCalled();

That is showing the following warning:

console.error
    Warning: An update to Button inside a test was not wrapped in act(...).

    When testing, code that causes React state updates should be wrapped into act(...):

If I wrap the click with act the warning is gone, but seems it's not a good practice to do that, because, in fact, testing library is doing an act internally in userEvent and in other methods. What can I do? Thanks.

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