Skip to content

Commit cfd21ba

Browse files
committed
fix(resizable): DLT-2097 guard MutationObserver constructor for test environments
1 parent d20c160 commit cfd21ba

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

packages/dialtone-vue/common/composables/useDOMCache.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,22 @@ export function useDOMCache(options: DOMCacheOptions = {}) {
259259

260260
nextTick(() => {
261261
if (!autoInvalidate) return;
262-
const root = typeof observeRoot === 'function' ? observeRoot() : observeRoot;
263-
const target = root ?? document.body;
264-
observer = new MutationObserver((mutations) => {
265-
if (shouldInvalidate(mutations)) invalidate();
266-
});
267-
observer.observe(target, {
268-
childList: true,
269-
subtree: true,
270-
attributes: true,
271-
attributeFilter: ['class', 'id', 'style'],
272-
});
262+
if (typeof MutationObserver === 'undefined' || typeof MutationObserver.prototype === 'undefined') return;
263+
try {
264+
const root = typeof observeRoot === 'function' ? observeRoot() : observeRoot;
265+
const target = root ?? document.body;
266+
observer = new MutationObserver((mutations) => {
267+
if (shouldInvalidate(mutations)) invalidate();
268+
});
269+
observer.observe(target, {
270+
childList: true,
271+
subtree: true,
272+
attributes: true,
273+
attributeFilter: ['class', 'id', 'style'],
274+
});
275+
} catch {
276+
// MutationObserver unavailable or mocked improperly (test environments)
277+
}
273278
});
274279

275280
onUnmounted(() => { cleanup(); });

0 commit comments

Comments
 (0)