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.
This commit is contained in:
Robin Ward 2022-01-27 15:53:53 -05:00
parent 23d7fcf9a1
commit 3350657553
1 changed files with 14 additions and 2 deletions

View File

@ -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("*");