Skip to content

Commit e682dff

Browse files
authored
Merge pull request #6 from Patternslib/jest-dialog
Define the close, show and showModal methods in dialog elements.
2 parents 0060daa + 3b59aed commit e682dff

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

jest/setup-tests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,17 @@ Object.defineProperty(window, "matchMedia", {
9999
dispatchEvent: jest.fn(),
100100
})),
101101
});
102+
103+
// Define the close, show and showModal methods in dialog elements.
104+
// Also see:
105+
// - https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement
106+
// - https://github.com/jsdom/jsdom/issues/3294
107+
HTMLDialogElement.prototype.close = jest.fn().mockImplementation(function () {
108+
this.open = false;
109+
});
110+
HTMLDialogElement.prototype.show = jest.fn().mockImplementation(function () {
111+
this.open = true;
112+
});
113+
HTMLDialogElement.prototype.showModal = jest.fn().mockImplementation(function () {
114+
this.open = true;
115+
});

0 commit comments

Comments
 (0)