Skip to content

Commit

Permalink
add test for anonymous custom element
Browse files Browse the repository at this point in the history
  • Loading branch information
KonnorRogers committed Jun 24, 2024
1 parent a04f2da commit 71cf828
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/pretty-format/src/__tests__/DOMElement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,14 @@ Testing.`;
customElements.define('custom-paragraph', CustomParagraphElement, {
extends: 'p',
});
customElements.define('anonymous-element', class extends HTMLElement {});

const parent = document.createElement('div');
parent.innerHTML = [
'<custom-element></custom-element>',
'<custom-extended-element></custom-extended-element>',
'<p is="custom-paragraph"></p>',
'<anonymous-element></anonymous-element>',
].join('');

expect(parent).toPrettyPrintTo(
Expand All @@ -373,6 +375,7 @@ Testing.`;
' <p',
' is="custom-paragraph"',
' />',
' <anonymous-element />',
'</div>',
].join('\n'),
);
Expand Down
9 changes: 6 additions & 3 deletions packages/pretty-format/src/plugins/DOMElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ const testHasAttribute = (val: any) => {
};

const isCustomElement = (val: any) => {
const { tagName } = val
return ((typeof tagName === 'string' && tagName.includes('-')) || testHasAttribute(val));
}
const {tagName} = val;
return (
(typeof tagName === 'string' && tagName.includes('-')) ||
testHasAttribute(val)
);
};

const testNode = (val: any) => {
const constructorName = val.constructor.name;
Expand Down

0 comments on commit 71cf828

Please sign in to comment.