From ca8fdba8f2495c35d48b20fdd502e4e8df8f66f0 Mon Sep 17 00:00:00 2001 From: Christopher Dieringer Date: Sat, 6 Mar 2021 19:02:23 -0800 Subject: [PATCH] docs(react-testing-library): warn about afterEach auto cleanup footgun --- docs/react-testing-library/setup.mdx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/react-testing-library/setup.mdx b/docs/react-testing-library/setup.mdx index d94a8c540..224c086b0 100644 --- a/docs/react-testing-library/setup.mdx +++ b/docs/react-testing-library/setup.mdx @@ -19,6 +19,16 @@ require that you use Jest). Adding options to your global test config can simplify the setup and teardown of tests in individual files. +## Safe cleanup + +`React Testing Library` will auto `cleanup` rendered components in all +frameworks that expose an `afterEach` API. Be warned, however, that any `async` +`afterEach` handlers you register that _defers_ the RTL `cleanup` call will +leave opporitunity for your rendered components to continue process react state +updates and emit `act()` errors. If you implement custom async `afterEach` +handlers, it is recommended to call `cleanup` explicity before any async +behavior. + ## Custom Render It's often useful to define a custom render method that includes things like