loculus-project / loculus

An open-source software package to power microbial genomic databases
https://loculus.org
GNU Affero General Public License v3.0
33 stars 1 forks source link

wrap react tests in act #1610

Open theosanderson opened 5 months ago

theosanderson commented 5 months ago

Our unit test logs have a lot of:

Warning: An update to Fe 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 Fe 

https://github.com/loculus-project/loculus/actions/runs/8668362408/job/23773286148

We should implement this. This may prevent some hacks I had to do to stop tests flaking which involved adding timeouts between steps.

theosanderson commented 5 months ago

The solution to this seems to be not handling the act wrapping ourselves but using await findByRole instead of getByRole (and similar renames throughout) which does the wrapping itself. https://medium.com/@AbbasPlusPlus/react-testing-library-understanding-act-and-when-to-use-it-301bd06fd1bc

theosanderson commented 5 months ago

(We probably want to tackle this soon as the spam makes dev hard)