commit db0a1bb9944c78cf37b8953a9158f2367c601e31
parent c903ab15c41e23804545dce3107c274c579584eb
Author: Maxx Crawford <mcrawford@mozilla.com>
Date: Fri, 9 Jan 2026 04:30:06 +0000
Bug 2008770 - Fix HTMLDialogElement mock to prevent coverage reporting failures. r=home-newtab-reviewers,nina-py
Differential Revision: https://phabricator.services.mozilla.com/D278057
Diffstat:
3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/browser/extensions/newtab/test/unit/content-src/components/ModalOverlay.test.jsx b/browser/extensions/newtab/test/unit/content-src/components/ModalOverlay.test.jsx
@@ -2,6 +2,18 @@ import { ModalOverlayWrapper } from "content-src/components/ModalOverlay/ModalOv
import { mount } from "enzyme";
import React from "react";
+// Patch dialog element's .showModal()/close() functions to prevent errors in tests
+before(() => {
+ if (typeof HTMLDialogElement !== "undefined") {
+ HTMLDialogElement.prototype.showModal = function () {
+ this.open = true;
+ };
+ HTMLDialogElement.prototype.close = function () {
+ this.open = false;
+ };
+ }
+});
+
describe("ModalOverlayWrapper", () => {
let sandbox;
beforeEach(() => {
diff --git a/browser/extensions/newtab/test/unit/content-src/components/TopSites.test.jsx b/browser/extensions/newtab/test/unit/content-src/components/TopSites.test.jsx
@@ -25,6 +25,18 @@ import { TopSiteFormInput } from "content-src/components/TopSites/TopSiteFormInp
import { _TopSites as TopSites } from "content-src/components/TopSites/TopSites";
import { ContextMenuButton } from "content-src/components/ContextMenu/ContextMenuButton";
+// Patch dialog element's .showModal()/close() functions to prevent errors in tests
+before(() => {
+ if (typeof HTMLDialogElement !== "undefined") {
+ HTMLDialogElement.prototype.showModal = function () {
+ this.open = true;
+ };
+ HTMLDialogElement.prototype.close = function () {
+ this.open = false;
+ };
+ }
+});
+
const perfSvc = {
mark() {},
getMostRecentAbsMarkStartByName() {},
diff --git a/browser/extensions/newtab/test/unit/unit-entry.js b/browser/extensions/newtab/test/unit/unit-entry.js
@@ -37,17 +37,6 @@ chai.use(chaiAssertions);
const overrider = new GlobalOverrider();
-// Patch dialog element's .showModal()/close() functions to prevent errors in tests
-// Some test environments may not have proper HTMLDialogElement support
-if (typeof HTMLDialogElement !== "undefined") {
- HTMLDialogElement.prototype.showModal = function () {
- this.open = true;
- };
- HTMLDialogElement.prototype.close = function () {
- this.open = false;
- };
-}
-
const RemoteSettings = name => ({
get: () => {
if (name === "attachment") {