Created
May 29, 2017 04:03
-
-
Save tbranyen/c3c30b7a3e5ffd3d42a1d43dd724abc0 to your computer and use it in GitHub Desktop.
Web Components <3 JSDOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm i jsdom-wc@11.0.0-alpha-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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