UNPKG

@schukai/monster

Version:

Monster is a simple library for creating fast, robust and lightweight websites.

44 lines (34 loc) 869 B
'use strict'; let addedNodes, mutationobserver; function init() { addedNodes = []; mutationobserver = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.type === 'childList' && mutation.removedNodes) { mutation.addedNodes.forEach((n) => { if (n instanceof HTMLElement) { addedNodes.push(n); } }) } }); }); } /** * */ export function initMutationObserverForTesting() { if (mutationobserver === undefined) { init() } mutationobserver.observe(document.querySelector('head'), {childList: true}); } /** * */ export function cleanupDOMFromTesting() { mutationobserver.disconnect(); for (const n of addedNodes) { n.remove(); } }