-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case for shadowrootmode open vs. closed
- Loading branch information
1 parent
9ea019b
commit f1d726c
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Use Case | ||
* Run wcc against two custom elements, one with an open shadow root and one with a closed shadow root | ||
* | ||
* User Result | ||
* Should return the expected HTML output based on the shadow root mode of each component | ||
* | ||
* User Workspace | ||
* src/ | ||
* index.js | ||
*/ | ||
|
||
import chai from 'chai'; | ||
import { JSDOM } from 'jsdom'; | ||
import { renderToString } from '../../../src/wcc.js'; | ||
|
||
const expect = chai.expect; | ||
|
||
describe('Run WCC For ', function () { | ||
const LABEL = 'Custom Elements w/ closed and open shadowrootmode'; | ||
let dom; | ||
|
||
before(async function () { | ||
const { html } = await renderToString(new URL('./src/index.js', import.meta.url)); | ||
console.log('hello', html); | ||
dom = new JSDOM(html); | ||
}); | ||
|
||
describe(LABEL, function () { | ||
it('should have exactly one open shadowrootmode template', function () { | ||
expect( | ||
dom.window.document.querySelectorAll('open-shadow-component template[shadowrootmode="open"]').length | ||
).to.equal(1); | ||
}); | ||
|
||
it('should have exactly one closed shadowrootmode template', function () { | ||
expect( | ||
dom.window.document.querySelectorAll('closed-shadow-component template[shadowrootmode="closed"]').length | ||
).to.equal(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default class ClosedShadowComponent extends HTMLElement { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
async connectedCallback() { | ||
|
||
if (!this.shadowRoot) { | ||
this.attachShadow({ mode: 'closed' }); | ||
const template = document.createElement('template'); | ||
template.innerHTML = ` | ||
<h1>Shadow Root Closed</h1> | ||
`; | ||
this.shadowRoot.appendChild(template.content.cloneNode(true)); | ||
} | ||
} | ||
} | ||
|
||
customElements.define('closed-shadow-component', ClosedShadowComponent); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import './open-shadow-component.js'; | ||
import './closed-shadow-component.js'; | ||
|
||
export default class HomePage extends HTMLElement { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
connectedCallback() { | ||
this.innerHTML = ` | ||
<open-shadow-component></open-shadow-component> | ||
<closed-shadow-component></closed-shadow-component> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('wcc-home', HomePage); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default class OpenShadowComponent extends HTMLElement { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
async connectedCallback() { | ||
|
||
if (!this.shadowRoot) { | ||
this.attachShadow({ mode: 'open' }); | ||
const template = document.createElement('template'); | ||
template.innerHTML = ` | ||
<h1>Shadow Root Open</h1> | ||
`; | ||
this.shadowRoot.appendChild(template.content.cloneNode(true)); | ||
} | ||
} | ||
} | ||
|
||
customElements.define('open-shadow-component', OpenShadowComponent); |