Skip to content

Commit

Permalink
capricorn86#451@patch: Fixes missing innerHTML in html-template.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mas0nShi committed Jun 15, 2022
1 parent f9d55eb commit 63a4800
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Expand Up @@ -3,6 +3,7 @@ import HTMLElement from '../html-element/HTMLElement';
import IDocumentFragment from '../document-fragment/IDocumentFragment';
import INode from '../node/INode';
import IHTMLTemplateElement from './IHTMLTemplateElement';
import XMLSerializer from '../../xml-serializer/XMLSerializer';

/**
* HTML Template Element.
Expand All @@ -13,6 +14,29 @@ import IHTMLTemplateElement from './IHTMLTemplateElement';
export default class HTMLTemplateElement extends HTMLElement implements IHTMLTemplateElement {
private _contentElement: IDocumentFragment = null;

/**
* Sets inner HTML.
*
* @param html HTML.
*/
public set innerHTML(html: string) {
super.innerHTML = html;
}

/**
* Returns inner HTML.
*
* @returns HTML.
*/
public get innerHTML(): string {
const xmlSerializer = new XMLSerializer();
let xml = '';
for (const node of this.content.childNodes) {
xml += xmlSerializer.serializeToString(node);
}
return xml;
}

/**
* Returns the content.
*
Expand Down
@@ -0,0 +1,25 @@
import Window from '../../../src/window/Window';
import Document from '../../../src/nodes/document/Document';
import HTMLTemplateElement from '../../../src/nodes/html-template-element/HTMLTemplateElement';

describe('HTMLTemplateElement', () => {
let window: Window;
let document: Document;
let element: HTMLTemplateElement;

beforeEach(() => {
window = new Window();
document = window.document;
element = <HTMLTemplateElement>document.createElement('template');
});

afterEach(() => {
jest.restoreAllMocks();
});

it('InnerHTML', () => {
const div = '<div>happy-dom is cool!</div>';
element.innerHTML = div;
expect(element.innerHTML).toBe(div);
});
});

0 comments on commit 63a4800

Please sign in to comment.