From 9250b25b09c71d806a8137e606f05350b5a414ff Mon Sep 17 00:00:00 2001 From: Sune Simonsen Date: Mon, 25 Nov 2019 18:55:06 +0100 Subject: [PATCH 1/2] Make a failing test to show the problem --- test/index.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/index.spec.js b/test/index.spec.js index e7feb4e9..6b465082 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1678,6 +1678,22 @@ describe('unexpected-dom', () => { ` ); }); + + describe('on nodes of different types', () => { + it('should fail', () => { + expect(() => { + expect( + parseHtmlNode( + '' + ), + 'to equal', + parseHtmlDocument( + '

Tournament

' + ) + ); + }, 'to throw'); + }); + }); }); describe('on text nodes', () => { From 9e2ab35c6d39390eff40416a4de99a1622ff87de Mon Sep 17 00:00:00 2001 From: Sune Simonsen Date: Mon, 25 Nov 2019 19:04:26 +0100 Subject: [PATCH 2/2] Compare the node type when comparing DOM nodes for equality --- src/index.js | 2 +- test/index.spec.js | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/index.js b/src/index.js index 5bfcec25..f3ceedc3 100644 --- a/src/index.js +++ b/src/index.js @@ -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( diff --git a/test/index.spec.js b/test/index.spec.js index 6b465082..5e577c99 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1681,17 +1681,26 @@ describe('unexpected-dom', () => { describe('on nodes of different types', () => { it('should fail', () => { - expect(() => { - expect( - parseHtmlNode( - '' - ), - 'to equal', - parseHtmlDocument( - '

Tournament

' - ) - ); - }, 'to throw'); + expect( + () => { + expect( + parseHtmlNode( + '' + ), + 'to equal', + parseHtmlDocument( + '

Tournament

' + ) + ); + }, + 'to throw an error satisfying to equal snapshot', + expect.unindent` + expected + to equal ... + + Mismatching constructors HTMLUListElement should be Document + ` + ); }); }); });