From 8f440c0acb36d27a7828fd896c0c70ff7e8f8200 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 27 Jan 2026 02:04:04 +0000 Subject: [PATCH] test(infra): mock web APIs for JSDOM and fix comments test assertions - Mock HTMLMediaElement.prototype.pause/load and window.scrollTo in test setup to prevent JSDOM "Not implemented" errors. - Fix VideoModal mock in comments tests to preserve prototype chain (using Object.create instead of spread). - Add missing childrenByParent map to comments test payloads to fix rendering assertions. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- tests/video-modal-accessibility.test.mjs | 24 ++++++++++++++++++++++++ tests/video-modal-comments.test.mjs | 12 ++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tests/video-modal-accessibility.test.mjs b/tests/video-modal-accessibility.test.mjs index 438e93ce..c99974c1 100644 --- a/tests/video-modal-accessibility.test.mjs +++ b/tests/video-modal-accessibility.test.mjs @@ -33,6 +33,16 @@ export async function setupModal({ lazyLoad = false } = {}) { globalThis.Event = window.Event; globalThis.Node = window.Node; globalThis.EventTarget = window.EventTarget; + + if (typeof window.HTMLMediaElement !== "undefined") { + window.HTMLMediaElement.prototype.pause = function () {}; + window.HTMLMediaElement.prototype.load = function () {}; + } + if (typeof window.HTMLVideoElement !== "undefined") { + window.HTMLVideoElement.prototype.pause = function () {}; + window.HTMLVideoElement.prototype.load = function () {}; + } + try { Object.defineProperty(globalThis, "navigator", { value: window.navigator, @@ -142,6 +152,8 @@ export async function setupModal({ lazyLoad = false } = {}) { }; } + window.scrollTo = () => {}; + applyDesignSystemAttributes(document); if (!window.ResizeObserver) { @@ -432,6 +444,16 @@ async function setupPlaybackHarness() { globalThis.Event = window.Event; globalThis.Node = window.Node; globalThis.EventTarget = window.EventTarget; + + if (typeof window.HTMLMediaElement !== "undefined") { + if (!window.HTMLMediaElement.prototype.pause) { + window.HTMLMediaElement.prototype.pause = function () {}; + } + if (!window.HTMLMediaElement.prototype.load) { + window.HTMLMediaElement.prototype.load = function () {}; + } + } + try { Object.defineProperty(globalThis, "navigator", { value: window.navigator, @@ -531,6 +553,8 @@ async function setupPlaybackHarness() { }; } + window.scrollTo = () => {}; + window.NostrTools = { nip19: { neventEncode: () => "nevent1example", diff --git a/tests/video-modal-comments.test.mjs b/tests/video-modal-comments.test.mjs index 147b554b..b34e4f6e 100644 --- a/tests/video-modal-comments.test.mjs +++ b/tests/video-modal-comments.test.mjs @@ -247,12 +247,10 @@ test( t.after(cleanup); const visibilityCalls = []; - const instrumentedModal = { - ...modal, - setCommentsVisibility: (isVisible) => { - visibilityCalls.push(isVisible); - modal.setCommentsVisibility(isVisible); - }, + const instrumentedModal = Object.create(modal); + instrumentedModal.setCommentsVisibility = (isVisible) => { + visibilityCalls.push(isVisible); + modal.setCommentsVisibility(isVisible); }; const snapshot = { @@ -398,6 +396,7 @@ test( }, ], ]), + childrenByParent: new Map([[null, ["c1"]]]), commentIds: ["c1"], profiles: new Map([["ABCD", { name: "Mixed Case" }]]), }); @@ -477,6 +476,7 @@ test( }, ], ]), + childrenByParent: new Map([[null, ["comment-2"]]]), commentIds: ["comment-2"], profiles: new Map(), };