Question · JavaScript and React course · Module 13: Testing React

act() in React tests

When do you need to use act() by hand in React tests?

Answer options

  • When importing modules in tests
  • For state updates outside the RTL helpers, e.g. when advancing fake timers or calling a callback directly
  • Every time you use render() from React Testing Library
  • When writing snapshot tests

You can check the correct answer by solving this task in the CodeWorlds game.