From a757c96e39c4c39196b22d92c409534f99579b4e Mon Sep 17 00:00:00 2001 From: timdeschryver <28659384+timdeschryver@users.noreply.github.com> Date: Tue, 18 May 2021 18:18:25 +0200 Subject: [PATCH] fix: add safety check around process before cleaning up --- .../testing-library/src/lib/testing-library.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/projects/testing-library/src/lib/testing-library.ts b/projects/testing-library/src/lib/testing-library.ts index 3c3b86f7..98d0a2da 100644 --- a/projects/testing-library/src/lib/testing-library.ts +++ b/projects/testing-library/src/lib/testing-library.ts @@ -352,10 +352,16 @@ function cleanupAtFixture(fixture) { mountedFixtures.delete(fixture); } -if (typeof afterEach === 'function' && !process.env.ATL_SKIP_AUTO_CLEANUP) { - afterEach(async () => { - cleanup(); - }); +// if we're running in a test runner that supports afterEach +// then we'll automatically run cleanup afterEach test +// this ensures that tests run in isolation from each other +// if you don't like this, set the ATL_SKIP_AUTO_CLEANUP env variable to 'true' +if (typeof process === 'undefined' || !process.env?.ATL_SKIP_AUTO_CLEANUP) { + if (typeof afterEach === 'function') { + afterEach(() => { + cleanup(); + }); + } } // TODO: rename to `atl-wrapper-component`