From 4dde5b4508a51a928f7fd0da7a8356f88bec0a81 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 17 Nov 2021 02:39:19 -0800 Subject: [PATCH] Unmount React tree automatically in tests Summary: In the next diff, tests started to fail suddenly, probably as side effect of a changed module loading order or smthg, and started showing DOMs of different tests in test results. Figured that testing-library/react + jest doesn't automatically doesn't clean up the DOM as I hoped it would Reviewed By: timur-valiev Differential Revision: D32463402 fbshipit-source-id: 48d26badf774482e7320632e486dfc6358946484 --- desktop/scripts/jest-setup-after.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/desktop/scripts/jest-setup-after.js b/desktop/scripts/jest-setup-after.js index 21aac4e1a..1771b6aae 100644 --- a/desktop/scripts/jest-setup-after.js +++ b/desktop/scripts/jest-setup-after.js @@ -8,6 +8,7 @@ */ // jest-setup-after will run after Jest has been initialized, so that it can be adapted. +import {cleanup} from '@testing-library/react'; const test = global.test; if (!test) { @@ -31,3 +32,5 @@ test.unix = function local() { // eslint-disable-next-line return fn.apply(null, arguments); }; + +afterEach(cleanup);