Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class HelloElement extends HTMLElement {
connectedCallback() {
this.innerHTML = this.render('Nettleser: Hei');
}
render(text) {
return `<h1> ${text} </h1>`;
}
}
customElements.define('hello-element', HelloElement);
global.HTMLElement = class EmptyHTMLElement {};
const helloElement = new HelloElement();
const serverHtml = `
<hello-element>
${helloElement.render('Server: Hei')}
</hello-element>`;
function renderElement(elementConstructor, tagName, props) {
const element = new elementConstructor();
const html = element.render(props);
return `<${tagName}> ${html} </${tagName}>`;
}
const html = renderElement(HelloElement, 'hello-element', 'Server: Hei');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment