Skip to content

Instantly share code, notes, and snippets.

@tbranyen
Created May 29, 2017 04:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbranyen/c3c30b7a3e5ffd3d42a1d43dd724abc0 to your computer and use it in GitHub Desktop.
Save tbranyen/c3c30b7a3e5ffd3d42a1d43dd724abc0 to your computer and use it in GitHub Desktop.
Web Components <3 JSDOM
npm i jsdom-wc@11.0.0-alpha-1
const { JSDOM } = require('jsdom-wc');
const { window } = new JSDOM(`<!DOCTYPE html>`);
Object.assign(global, {
document: window.document,
HTMLElement: window.HTMLElement,
customElements: window.customElements,
window,
});
class BoldComponent extends HTMLElement {
connectedCallback() {
this.innerHTML = `<b>${this.innerHTML}</b>`;
}
}
customElements.define('bold-component', BoldComponent);
document.body.innerHTML = `
<bold-component>What a time to be...</bold-component>
`;
console.log(document.body.outerHTML);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment