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 support for an ignore tag in addition to the ignore tag #205

Merged
merged 1 commit into from
Apr 3, 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
12 changes: 9 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,15 @@ module.exports = {
return { name: node.nodeName };
} else if (node.nodeType === 1) {
// DOMElement
var result = {
name: isHtml ? node.nodeName.toLowerCase() : node.nodeName
};
var name = isHtml ? node.nodeName.toLowerCase() : node.nodeName;

if (name === 'ignore') {
// Ignore subtree
return {};
}

var result = { name: name };

if (node.attributes) {
result.attributes = {};
for (var i = 0; i < node.attributes.length; i += 1) {
Expand Down
52 changes: 51 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ describe('unexpected-dom', function() {
);
});

describe('and it contain an <ignore/> tag', function() {
describe('and it contain an ignore comment', function() {
it('ignores that subtree', () => {
expect(
[
Expand Down Expand Up @@ -1434,6 +1434,56 @@ 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></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></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></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></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