Skip to content

Commit

Permalink
Compare the node type when comparing DOM nodes for equality
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Nov 25, 2019
1 parent 9250b25 commit 9e2ab35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ module.exports = {
);
},
equal(a, b) {
return a.nodeValue === b.nodeValue;
return a.nodeType === b.nodeType && a.nodeValue === b.nodeValue;
},
inspect(element, depth, output) {
return output.code(
Expand Down
31 changes: 20 additions & 11 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1681,17 +1681,26 @@ describe('unexpected-dom', () => {

describe('on nodes of different types', () => {
it('should fail', () => {
expect(() => {
expect(
parseHtmlNode(
'<ul><li>John</li><li class="winner">Jane</li><li>Annie</li></ul>'
),
'to equal',
parseHtmlDocument(
'<!DOCTYPE html><html><body><h1>Tournament</h1><ul><li>John</li><li>Jane</li><li class="winner">Annie</li></ul></body></html>'
)
);
}, 'to throw');
expect(
() => {
expect(
parseHtmlNode(
'<ul><li>John</li><li class="winner">Jane</li><li>Annie</li></ul>'
),
'to equal',
parseHtmlDocument(
'<!DOCTYPE html><html><body><h1>Tournament</h1><ul><li>John</li><li>Jane</li><li class="winner">Annie</li></ul></body></html>'
)
);
},
'to throw an error satisfying to equal snapshot',
expect.unindent`
expected <ul><li>John</li><li class="winner">Jane</li><li>Annie</li></ul>
to equal <!DOCTYPE html><html><head></head><body>...</body></html>
Mismatching constructors HTMLUListElement should be Document
`
);
});
});
});
Expand Down

0 comments on commit 9e2ab35

Please sign in to comment.