diff --git a/apps/browser/src/autofill/services/collect-autofill-content.service.spec.ts b/apps/browser/src/autofill/services/collect-autofill-content.service.spec.ts index 63f7c105d74..485c85dd014 100644 --- a/apps/browser/src/autofill/services/collect-autofill-content.service.spec.ts +++ b/apps/browser/src/autofill/services/collect-autofill-content.service.spec.ts @@ -2297,6 +2297,9 @@ describe("CollectAutofillContentService", () => { it("schedules a debounced check for new shadow roots", () => { jest.useFakeTimers(); + const div = document.createElement("div"); + document.body.appendChild(div); + const mutationRecord: MutationRecord = { type: "childList", addedNodes: document.querySelectorAll("div"), @@ -2305,7 +2308,7 @@ describe("CollectAutofillContentService", () => { nextSibling: null, oldValue: null, previousSibling: null, - removedNodes: null, + removedNodes: document.querySelectorAll("nonexistent"), target: document.body, }; collectAutofillContentService["currentLocationHref"] = window.location.href; @@ -2330,6 +2333,9 @@ describe("CollectAutofillContentService", () => { it("does not schedule duplicate shadow root checks when already pending", () => { jest.useFakeTimers(); + const div = document.createElement("div"); + document.body.appendChild(div); + const mutationRecord: MutationRecord = { type: "childList", addedNodes: document.querySelectorAll("div"), @@ -2338,7 +2344,7 @@ describe("CollectAutofillContentService", () => { nextSibling: null, oldValue: null, previousSibling: null, - removedNodes: null, + removedNodes: document.querySelectorAll("nonexistent"), target: document.body, }; collectAutofillContentService["currentLocationHref"] = window.location.href; diff --git a/apps/browser/src/autofill/services/dom-query.service.spec.ts b/apps/browser/src/autofill/services/dom-query.service.spec.ts index 6ff520dad2d..26cc731ffb3 100644 --- a/apps/browser/src/autofill/services/dom-query.service.spec.ts +++ b/apps/browser/src/autofill/services/dom-query.service.spec.ts @@ -233,6 +233,13 @@ describe("DomQueryService", () => { }); describe("checkForNewShadowRoots", () => { + beforeEach(() => { + // Clear any shadow roots from previous tests + document.body.innerHTML = ""; + // Reset the observed shadow roots set + domQueryService["observedShadowRoots"] = new WeakSet(); + }); + it("returns true when a shadow root is not in the observed set", () => { const customElement = document.createElement("custom-element"); customElement.attachShadow({ mode: "open" });