Skip to content

Commit

Permalink
nested HTML web component test
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Oct 1, 2024
1 parent 027034c commit 9ccf405
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function renderComponentRoots(tree, definitions) {
console.log('elementTree.childNodes', elementTree.childNodes);
console.log('node.childNodes', node.childNodes);

node.childNodes = node.childNodes.length === 0 && hasLight > 0 && !hasShadow
node.childNodes = node.childNodes.length === 0 && hasLight && !hasShadow
? elementTree.childNodes
: hasShadow
? [...elementTree.childNodes, ...node.childNodes]
Expand Down
6 changes: 4 additions & 2 deletions test/cases/html-web-component/html-web-component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ describe('Run WCC For ', function() {
expect(pictureFrame.length).to.equal(1);
});

it('should have the expected title attribute content in the heading of HTML', () => {
const heading = pictureFrame[0].querySelectorAll('.picture-frame .heading');
it('should have the expected title attribute content in a nested <wcc-caption> tag', () => {
const caption = pictureFrame[0].querySelectorAll('.picture-frame wcc-caption .caption');
const heading = caption[0].querySelectorAll('.heading');

expect(caption.length).to.equal(1);
expect(heading.length).to.equal(1);
expect(heading[0].textContent).to.equal('Greenwood');
});
Expand Down
13 changes: 13 additions & 0 deletions test/cases/html-web-component/src/components/caption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default class Caption extends HTMLElement {
connectedCallback() {
const title = this.getAttribute('title');

Check failure on line 3 in test/cases/html-web-component/src/components/caption.js

View workflow job for this annotation

GitHub Actions / build (20)

'title' is assigned a value but never used

Check failure on line 3 in test/cases/html-web-component/src/components/caption.js

View workflow job for this annotation

GitHub Actions / build (20)

'title' is assigned a value but never used

Check failure on line 3 in test/cases/html-web-component/src/components/caption.js

View workflow job for this annotation

GitHub Actions / build (18)

'title' is assigned a value but never used

Check failure on line 3 in test/cases/html-web-component/src/components/caption.js

View workflow job for this annotation

GitHub Actions / build (20)

'title' is assigned a value but never used

Check failure on line 3 in test/cases/html-web-component/src/components/caption.js

View workflow job for this annotation

GitHub Actions / build (20)

'title' is assigned a value but never used

this.innerHTML = `
<div class="caption">
${this.innerHTML}
</div>
`;
}
}

customElements.define('wcc-caption', Caption);
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import './caption.js';

export default class PictureFrame extends HTMLElement {
connectedCallback() {
const title = this.getAttribute('title');

this.innerHTML = `
<div class="picture-frame">
<h6 class="heading">${title}</h6>
<wcc-caption>
<h6 class="heading">${title}</h6>
</wcc-caption>
${this.innerHTML}
</div>
`;
Expand Down

0 comments on commit 9ccf405

Please sign in to comment.