1
resposta

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

Como solucionar este warning? Recebo quando executo os testes.

console.error node_modules/react-dom/cjs/react-dom.development.js:88 Warning: An update to App inside a test was not wrapped in act(...).

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

act(() => {
  /* fire events that update state */
});
/* assert on the output */

This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
    in App (at App.test.js:16)
1 resposta

Olá, Caique! Tudo bem?

Como dito em outro tópico similar, atualizar a versão da @testing-library/react pode resolver o problema.

Você pode fazer o seguinte:

npm install @testing-library/react@12.0.0

Depois, caso tenha algum problema no arquivo AppIntegracoes.test.jsrelacionado a MutationObserver, você pode fazer uma simples correção para que tudo volte a funcionar:

npm install --save-dev @sheerun/mutationobserver-shim
# yarn add --dev @sheerun/mutationobserver-shim

E depois, no arquivo setupTests.js, adicionar as linhas:

import MutationObserver from '@sheerun/mutationobserver-shim'
window.MutationObserver = MutationObserver

Espero que ajude!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software