Skip to content
masterclass Buddy

React Testing Library · Function

cleanup

cleanup unmounts React trees created by render and clears the DOM. It runs automatically after each test when the test framework provides a global afterEach hook; otherwise, call it yourself.

Last updated

Syntax

cleanup()

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • render
  • afterEach
  • @testing-library/react/pure
  • @testing-library/react/dont-cleanup-after-each
  • RTL_SKIP_AUTO_CLEANUP

Source: API | Testing Library. Checked 2026-11-03.