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

Support ignoring subtrees in to satisfy #198

Merged
merged 2 commits into from
Mar 18, 2018
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 lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,10 @@ module.exports = {
);

function convertDOMNodeToSatisfySpec(node, isHtml) {
if (node.nodeType === 10) {
if (node.nodeType === 8 && node.nodeValue.trim() === 'ignore') {
// Ignore subtree
return {};
} else if (node.nodeType === 10) {
// HTMLDocType
return { name: node.nodeName };
} else if (node.nodeType === 1) {
Expand Down
48 changes: 48 additions & 0 deletions test/unexpected-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,54 @@ describe('unexpected-dom', function() {
' ]'
);
});

describe('and it contain an <ignore/> tag', function() {
it('ignores that subtree', () => {
expect(
[
'<div foo="bar">foo</div>',
'<div><div>bar</div></div>',
'<div>baz</div>'
].join('\n'),
'when parsed as HTML fragment to satisfy',
parseHtmlFragment(
['<div>foo</div>', '<!--ignore-->', '<div>baz</div>'].join('\n')
)
);
});

it('inspects correctly when another subtree', function() {
expect(
function() {
expect(
'<div foo="bar">foo</div><div><div>bar</div></div><div>baz</div>',
'when parsed as HTML fragment to satisfy',
parseHtmlFragment(
'<div foo="bar">foo!</div><!--ignore--><div>baz</div>'
)
);
},
'to throw',
[
'expected \'<div foo="bar">foo</div><div><div>bar</div></div><div>baz</div>\'',
'when parsed as HTML fragment to satisfy DocumentFragment[NodeList[ <div foo="bar">foo!</div>, <!--ignore-->, <div>baz</div> ]]',
' expected DocumentFragment[NodeList[ <div foo="bar">foo</div>, <div><div>...</div></div>, <div>baz</div> ]]',
' to satisfy DocumentFragment[NodeList[ <div foo="bar">foo!</div>, <!--ignore-->, <div>baz</div> ]]',
'',
' NodeList[',
' <div foo="bar">',
" foo // should equal 'foo!'",
' //',
' // -foo',
' // +foo!',
' </div>,',
' <div><div>...</div></div>,',
' <div>baz</div>',
' ]'
].join('\n')
);
});
});
});

describe('with an array as the value', function() {
Expand Down