From 33506575533c269b2121f018d535b210a153d122 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 27 Jan 2022 15:53:53 -0500 Subject: [PATCH] DEV: Clean up HTML state between tests A bunch of tests were leaving leftovers in the DOM like class names, custom styles and scroll positions. This ensures they are cleared between tests. --- .../javascripts/discourse/tests/setup-tests.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index 05702fe8494..ee378e1ceb0 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -342,8 +342,20 @@ function setupTestsCommon(application, container, config) { resetPretender(); clearPresenceState(); - // Destroy any modals - $(".modal-backdrop").remove(); + // Clean up the DOM. Some tests might leave extra classes or elements behind. + Array.from(document.getElementsByClassName("modal-backdrop")).forEach((e) => + e.remove() + ); + document.body.removeAttribute("class"); + let html = document.getElementsByTagName("html")[0]; + html.removeAttribute("class"); + html.removeAttribute("style"); + let testing = document.getElementById("ember-testing"); + testing.removeAttribute("class"); + testing.removeAttribute("style"); + let testContainer = document.getElementById("ember-testing-container"); + testContainer.scrollTop = 0; + flushMap(); MessageBus.unsubscribe("*");