Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,5 @@ export function isNumber(str: string): boolean {
* Checks if the given element is part of the document tree.
*/
export function isInDocument(element: Element): boolean {
return element.ownerDocument === document;
return document.contains(element);
}
14 changes: 14 additions & 0 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { jest } from "@jest/globals";
import {
SETTINGS_DOMAIN_BLACKLIST,
addDomainToList,
isInDocument,
isDomainOnList,
removeDomainFromList,
} from "../src/shared/utils";
Expand Down Expand Up @@ -89,3 +90,16 @@ describe("shared utils domain list handling", () => {
expect(getMock).toHaveBeenCalledWith(SETTINGS_DOMAIN_BLACKLIST);
});
});

describe("shared utils DOM helpers", () => {
test("isInDocument returns false for detached nodes and true only while attached", () => {
const element = document.createElement("div");
expect(isInDocument(element)).toBe(false);

document.body.appendChild(element);
expect(isInDocument(element)).toBe(true);

element.remove();
expect(isInDocument(element)).toBe(false);
});
});
Loading