Skip to content

Commit

Permalink
Update DOMElement.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
KonnorRogers authored Jun 24, 2024
1 parent a4411d1 commit ea52ca4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/pretty-format/src/plugins/DOMElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,27 @@ const testHasAttribute = (val: any) => {
}
};

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

const testNode = (val: any) => {
const constructorName = val.constructor.name;
const {nodeType, tagName} = val;
const isCustomElement =
(typeof tagName === 'string' && tagName.includes('-')) ||
testHasAttribute(val);
const {nodeType} = val;

return (
(nodeType === ELEMENT_NODE &&
(ELEMENT_REGEXP.test(constructorName) || isCustomElement)) ||
(ELEMENT_REGEXP.test(constructorName) || isCustomElement(val))) ||
(nodeType === TEXT_NODE && constructorName === 'Text') ||
(nodeType === COMMENT_NODE && constructorName === 'Comment') ||
(nodeType === FRAGMENT_NODE && constructorName === 'DocumentFragment')
);
};

export const test: NewPlugin['test'] = (val: any) =>
val?.constructor && testNode(val);
(val?.constructor?.name || isCustomElement(val)) && testNode(val);

type HandledType = Element | Text | Comment | DocumentFragment;

Expand Down

0 comments on commit ea52ca4

Please sign in to comment.