Skip to content

Commit ea52ca4

Browse files
authored
Update DOMElement.ts
1 parent a4411d1 commit ea52ca4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/pretty-format/src/plugins/DOMElement.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,27 @@ const testHasAttribute = (val: any) => {
3030
}
3131
};
3232

33+
const isCustomElement = (val: any) => {
34+
const { tagName } = val
35+
return (typeof tagName === 'string' && tagName.includes('-')) ||
36+
testHasAttribute(val);
37+
}
38+
3339
const testNode = (val: any) => {
3440
const constructorName = val.constructor.name;
35-
const {nodeType, tagName} = val;
36-
const isCustomElement =
37-
(typeof tagName === 'string' && tagName.includes('-')) ||
38-
testHasAttribute(val);
41+
const {nodeType} = val;
3942

4043
return (
4144
(nodeType === ELEMENT_NODE &&
42-
(ELEMENT_REGEXP.test(constructorName) || isCustomElement)) ||
45+
(ELEMENT_REGEXP.test(constructorName) || isCustomElement(val))) ||
4346
(nodeType === TEXT_NODE && constructorName === 'Text') ||
4447
(nodeType === COMMENT_NODE && constructorName === 'Comment') ||
4548
(nodeType === FRAGMENT_NODE && constructorName === 'DocumentFragment')
4649
);
4750
};
4851

4952
export const test: NewPlugin['test'] = (val: any) =>
50-
val?.constructor && testNode(val);
53+
(val?.constructor?.name || isCustomElement(val)) && testNode(val);
5154

5255
type HandledType = Element | Text | Comment | DocumentFragment;
5356

0 commit comments

Comments
 (0)