From 3b59aed8556c5103ada9efa175896f83e0fac6c0 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Thu, 15 Sep 2022 13:13:44 +0200 Subject: [PATCH] feat: Define the close, show and showModal methods in dialog elements. --- jest/setup-tests.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/jest/setup-tests.js b/jest/setup-tests.js index cd8dfe1..d9cc6cb 100644 --- a/jest/setup-tests.js +++ b/jest/setup-tests.js @@ -99,3 +99,17 @@ Object.defineProperty(window, "matchMedia", { dispatchEvent: jest.fn(), })), }); + +// Define the close, show and showModal methods in dialog elements. +// Also see: +// - https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement +// - https://github.com/jsdom/jsdom/issues/3294 +HTMLDialogElement.prototype.close = jest.fn().mockImplementation(function () { + this.open = false; +}); +HTMLDialogElement.prototype.show = jest.fn().mockImplementation(function () { + this.open = true; +}); +HTMLDialogElement.prototype.showModal = jest.fn().mockImplementation(function () { + this.open = true; +});