diff --git a/packages/happy-dom/src/config/NonImplemenetedElementClasses.ts b/packages/happy-dom/src/config/NonImplemenetedElementClasses.ts index 94b9dc358..6727c9415 100644 --- a/packages/happy-dom/src/config/NonImplemenetedElementClasses.ts +++ b/packages/happy-dom/src/config/NonImplemenetedElementClasses.ts @@ -21,7 +21,6 @@ export default [ 'HTMLDataElement', 'HTMLDataListElement', 'HTMLDetailsElement', - 'HTMLDialogElement', 'HTMLDirectoryElement', 'HTMLFieldSetElement', 'HTMLFontElement', diff --git a/packages/happy-dom/src/nodes/html-dialog-element/HTMLDialogElement.ts b/packages/happy-dom/src/nodes/html-dialog-element/HTMLDialogElement.ts index 0d69e9d94..130ecc469 100644 --- a/packages/happy-dom/src/nodes/html-dialog-element/HTMLDialogElement.ts +++ b/packages/happy-dom/src/nodes/html-dialog-element/HTMLDialogElement.ts @@ -9,12 +9,7 @@ import IHTMLDialogElement from './IHTMLDialogElement'; * https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement. */ export default class HTMLDialogElement extends HTMLElement implements IHTMLDialogElement { - /** - * Returns returnValue. - * - * @returns ReturnValue. - */ - public returnValue: string; + public returnValue = ''; /** * Returns open. @@ -28,12 +23,12 @@ export default class HTMLDialogElement extends HTMLElement implements IHTMLDialo /** * Closes the dialog. * - * @param returnValue ReturnValue. + * @param [returnValue] ReturnValue. */ - public close(returnValue?: string): void { + public close(returnValue = ''): void { this.removeAttributeNS(null, 'open'); this.returnValue = returnValue; - this.dispatchEvent(new Event('close', { bubbles: false, cancelable: false })); + this.dispatchEvent(new Event('close')); } /** diff --git a/packages/happy-dom/src/nodes/html-dialog-element/IHTMLDialogElement.ts b/packages/happy-dom/src/nodes/html-dialog-element/IHTMLDialogElement.ts index 4fbf8c455..2633a9356 100644 --- a/packages/happy-dom/src/nodes/html-dialog-element/IHTMLDialogElement.ts +++ b/packages/happy-dom/src/nodes/html-dialog-element/IHTMLDialogElement.ts @@ -9,7 +9,21 @@ import IHTMLElement from '../html-element/IHTMLElement'; export default interface IHTMLDialogElement extends IHTMLElement { open: boolean; returnValue: string; + + /** + * Closes the dialog. + * + * @param [returnValue] ReturnValue. + */ close(returnValue?: string): void; + + /** + * Shows the modal. + */ showModal(): void; + + /** + * Shows the dialog. + */ show(): void; } diff --git a/packages/happy-dom/test/nodes/html-dialog-element/HTMLDialogElement.test.ts b/packages/happy-dom/test/nodes/html-dialog-element/HTMLDialogElement.test.ts index 583008b68..601757b7c 100644 --- a/packages/happy-dom/test/nodes/html-dialog-element/HTMLDialogElement.test.ts +++ b/packages/happy-dom/test/nodes/html-dialog-element/HTMLDialogElement.test.ts @@ -1,20 +1,21 @@ -import { Event } from 'src'; -import Document from '../../../src/nodes/document/Document'; -import HTMLDialogElement from '../../../src/nodes/html-dialog-element/HTMLDialogElement'; +import Event from '../../../src/event/Event'; +import IHTMLDialogElement from '../../../src/nodes/html-dialog-element/IHTMLDialogElement'; import Window from '../../../src/window/Window'; +import IWindow from '../../../src/window/IWindow'; +import IDocument from '../../../src/nodes/document/IDocument'; describe('HTMLDialogElement', () => { - let window: Window; - let document: Document; - let element: HTMLDialogElement; + let window: IWindow; + let document: IDocument; + let element: IHTMLDialogElement; beforeEach(() => { window = new Window(); document = window.document; - element = document.createElement('dialog'); + element = document.createElement('dialog'); }); - describe('open', () => { + describe('get open()', () => { it('Should be closed by default', () => { expect(element.open).toBe(false); }); @@ -30,23 +31,25 @@ describe('HTMLDialogElement', () => { }); }); - describe('returnValue', () => { - it('Should be undefined by default', () => { - expect(element.returnValue).toBe(undefined); + describe('get returnValue()', () => { + it('Should be empty string by default', () => { + expect(element.returnValue).toBe(''); }); it('Should be set when close has been called with a return value', () => { element.close('foo'); expect(element.returnValue).toBe('foo'); }); + }); + describe('set returnValue()', () => { it('Should be possible to set manually', () => { element.returnValue = 'foo'; expect(element.returnValue).toBe('foo'); }); }); - describe('close', () => { + describe('close()', () => { it('Should be possible to close an open dialog', () => { element.show(); element.close(); @@ -92,7 +95,7 @@ describe('HTMLDialogElement', () => { }); }); - describe('showModal', () => { + describe('showModal()', () => { it('Should be possible to show a modal dialog', () => { element.showModal(); expect(element.open).toBe(true); @@ -100,7 +103,7 @@ describe('HTMLDialogElement', () => { }); }); - describe('show', () => { + describe('show()', () => { it('Should be possible to show a dialog', () => { element.show(); expect(element.open).toBe(true);