safe-wallet-web icon indicating copy to clipboard operation
safe-wallet-web copied to clipboard

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

Open compojoom opened this issue 1 year ago • 0 comments

Bug description

Most of the tests that deal with hooks trigger error similar to this:

  console.error
    Warning: An update to TestComponent 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://reactjs.org/link/wrap-tests-with-act
        at TestComponent (/safe/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:281:5)
        at ThemeProvider (/safe/safe-wallet-web/node_modules/@mui/private-theming/node/ThemeProvider/ThemeProvider.js:39:5)
        at ThemeProvider (/safe/safe-wallet-web/node_modules/@mui/system/ThemeProvider/ThemeProvider.js:50:5)
        at ThemeProvider (/safe/safe-wallet-web/node_modules/@mui/material/node/styles/ThemeProvider.js:21:14)
        at ThemeProvider (/safe/safe-wallet-web/node_modules/@mui/private-theming/node/ThemeProvider/ThemeProvider.js:39:5)
        at ThemeProvider (/safe/safe-wallet-web/node_modules/@mui/system/ThemeProvider/ThemeProvider.js:50:5)
        at ThemeProvider (/safe/safe-wallet-web/node_modules/@mui/material/node/styles/ThemeProvider.js:21:14)
        at children (/safe/safe-wallet-web/src/components/theme/SafeThemeProvider.tsx:15:58)
        at Provider (/safe/safe-wallet-web/node_modules/react-redux/lib/components/Provider.js:19:3)
        at HydrationWrapper (/safe/safe-wallet-web/src/store/storeHydrator.tsx:17:7)
        at children (/safe/safe-wallet-web/src/tests/test-utils.tsx:46:32)

This polutes the terminal and is pretty annoying when debugging failing tests.

Environment

terminal

Steps to reproduce

run yarn test and look at the output

Expected result

No warnings.

Obtained result

Screenshots

compojoom avatar Jan 15 '24 12:01 compojoom