From 796fe38913c7f0c2e735eca4a92c89bf564cc99a Mon Sep 17 00:00:00 2001 From: Ulas Date: Sun, 5 Apr 2026 13:06:18 +0200 Subject: [PATCH] fix(test): use bare matchMedia() instead of window.matchMedia() for Node ESM compat global.window assignment doesn't expose 'window' as an identifier in ESM modules in Node.js 22. matchMedia() is a global in browsers - no window. prefix needed. Co-Authored-By: Claude Sonnet 4.6 --- public/components/modal.js | 4 ++-- test-modal-utils.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/components/modal.js b/public/components/modal.js index b010ace..656a395 100644 --- a/public/components/modal.js +++ b/public/components/modal.js @@ -536,7 +536,7 @@ export function validateAll(formContainer) { export function btnSuccess(btn, originalLabel) { const label = originalLabel ?? btn.textContent; btn.classList.add('btn--success'); - const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; + const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches; if (!reducedMotion) { const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('width', '16'); @@ -579,7 +579,7 @@ export function btnLoading(btn) { * @param {HTMLButtonElement} btn */ export function btnError(btn) { - if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) { + if (matchMedia('(prefers-reduced-motion: reduce)').matches) { btn.classList.add('btn--error-static'); setTimeout(() => btn.classList.remove('btn--error-static'), 700); return; diff --git a/test-modal-utils.js b/test-modal-utils.js index 9aaae75..0928414 100644 --- a/test-modal-utils.js +++ b/test-modal-utils.js @@ -10,8 +10,8 @@ import assert from 'node:assert/strict'; // /i18n.js wird durch test-browser-loader.mjs gemockt (--loader Flag) const { wireBlurValidation, btnSuccess, btnError } = await import('./public/components/modal.js'); -// window.matchMedia und document.createElementNS werden von btnSuccess/btnError benötigt -global.window = { matchMedia: () => ({ matches: false }) }; +// matchMedia und document.createElementNS werden von btnSuccess/btnError benötigt +global.matchMedia = () => ({ matches: false }); const _makeSvgEl = (tag) => { const attrs = {};