-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test case for constructable stylesheets
- Loading branch information
1 parent
a4c553d
commit e3594ae
Showing
4 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
test/cases/constructable-stylesheet/constructabe-stylesheet.spec.js
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,38 @@ | ||
/* | ||
* Use Case | ||
* Run wcc against a custom element using constructible stylesheets. | ||
* | ||
* User Result | ||
* Should return the expected HTML and no error instatiating a CSSStyleSheet.. | ||
* | ||
* User Workspace | ||
* src/ | ||
* components/ | ||
* header/ | ||
* header.js | ||
* pages/ | ||
* 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 = 'Constructible Stylesheets usage'; | ||
let dom; | ||
|
||
before(async function() { | ||
const { html } = await renderToString(new URL('./src/pages/index.js', import.meta.url)); | ||
|
||
dom = new JSDOM(html); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
it('should have one top level <wcc-header> element with a <template> with an open shadowroot', function() { | ||
expect(dom.window.document.querySelectorAll('wcc-header template[shadowrootmode="open"]').length).to.equal(1); | ||
expect(dom.window.document.querySelectorAll('template').length).to.equal(1); | ||
}); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
test/cases/constructable-stylesheet/src/components/header/header.js
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,23 @@ | ||
const template = document.createElement('template'); | ||
|
||
template.innerHTML = ` | ||
<header> | ||
<h1>Welcome to my website!</h1> | ||
</header> | ||
`; | ||
|
||
const sheet = new CSSStyleSheet(); | ||
sheet.replaceSync('li{color:red;}'); | ||
|
||
export default class Header extends HTMLElement { | ||
connectedCallback() { | ||
if (!this.shadowRoot) { | ||
this.attachShadow({ mode: 'open' }); | ||
this.shadowRoot.appendChild(template.content.cloneNode(true)); | ||
} | ||
|
||
this.shadowRoot.adoptedStyleSheets = [sheet]; | ||
} | ||
} | ||
|
||
customElements.define('wcc-header', Header); |
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,10 @@ | ||
import '../components/header/header.js'; | ||
|
||
export default class HomePage extends HTMLElement { | ||
connectedCallback() { | ||
this.innerHTML = ` | ||
<wcc-header></wcc-header> | ||
<h1>Home Page</h1> | ||
`; | ||
} | ||
} |
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