Skip to content

Commit

Permalink
fix(pretty-format): handle tagName not being a string (#10397)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Aug 12, 2020
1 parent 80985ed commit cf07d11
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[pretty-format]` Handle `tagName` not being a string ([#10397](https://github.com/facebook/jest/pull/10397))

### Chore & Maintenance

### Performance
Expand Down
18 changes: 18 additions & 0 deletions packages/pretty-format/src/__tests__/DOMElement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,22 @@ Testing.`;
{maxDepth: 2},
);
});

it('handles `tagName` not being a string', () => {
expect({
name: 'value',
tagName: {text: 'param'},
type: 'string',
}).toPrettyPrintTo(
[
'Object {',
' "name": "value",',
' "tagName": Object {',
' "text": "param",',
' },',
' "type": "string",',
'}',
].join('\n'),
);
});
});
6 changes: 4 additions & 2 deletions packages/pretty-format/src/plugins/DOMElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ const ELEMENT_REGEXP = /^((HTML|SVG)\w*)?Element$/;

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

return (
(nodeType === ELEMENT_NODE &&
Expand Down

0 comments on commit cf07d11

Please sign in to comment.