Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add equals methods for DOMDocument and DOMDocumentFragment #301

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ module.exports = {
}
return output;
},
equal(a, b, equal) {
return equal(a.childNodes, b.childNodes);
},
diff(actual, expected, output, diff, inspect, equal) {
output.inline = true;
output.append(
Expand Down Expand Up @@ -498,7 +501,7 @@ module.exports = {
.text(']');
},
equal(a, b, equal) {
return this.baseType.equal(a, b) && equal(a.childNodes, b.childNodes);
return equal(a.childNodes, b.childNodes);
},
diff(actual, expected, output, diff, inspect, equal) {
output.inline = true;
Expand Down
54 changes: 54 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,60 @@ describe('unexpected-dom', () => {
});
});

describe('on DOM documents', () => {
it('should succeeds if they are equal', () => {
expect(
parseHtmlDocument(
'<!DOCTYPE html><html><body><h1>Tournament</h1><ul><li>John</li><li class="winner">Jane</li><li>Annie</li></ul></body></html>'
),
'to equal',
parseHtmlDocument(
'<!DOCTYPE html><html><body><h1>Tournament</h1><ul><li>John</li><li class="winner">Jane</li><li>Annie</li></ul></body></html>'
)
);
});

it('should fail if they are not equal', () => {
expect(
() => {
expect(
parseHtmlDocument(
'<!DOCTYPE html><html><body><h1>Tournament</h1><ul><li>John</li><li class="winner">Jane</li><li>Annie</li></ul></body></html>'
),
'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 <!DOCTYPE html><html><head></head><body>...</body></html>
to equal <!DOCTYPE html><html><head></head><body>...</body></html>

<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>Tournament</h1>
<ul>
<li>John</li>
<li class="winner" // should be removed
>
Jane
</li>
<li // missing class="winner"
>
Annie
</li>
</ul>
</body>
</html>
`
);
});
});

describe('on DOM document fragments', () => {
it('should succeeds if they are equal', () => {
expect(
Expand Down