Skip to content

Commit

Permalink
fix(html-namespace-matches): work with serial virtual nodes (#2398)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored Jul 20, 2020
1 parent e2537ef commit 18c22fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/rules/html-namespace-matches.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function htmlNamespaceMatches(node) {
return node.namespaceURI === 'http://www.w3.org/1999/xhtml';
import svgNamespaceMatches from './svg-namespace-matches';

function htmlNamespaceMatches(node, virtualNode) {
return !svgNamespaceMatches(node, virtualNode);
}

export default htmlNamespaceMatches;
33 changes: 33 additions & 0 deletions test/rule-matches/html-namespace-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,37 @@ describe('html-namespace-matches', function() {
var virtualNode = axe.utils.getNodeFromTree(axe._tree[0], node);
assert.isFalse(rule.matches(node, virtualNode));
});

describe('Serial Virtual Node', function() {
it('returns true when passed an HTML element', function() {
var serialNode = new axe.SerialVirtualNode({
nodeName: 'h1'
});
serialNode.parent = null;

assert.isTrue(rule.matches(null, serialNode));
});

it('returns true when passed a custom HTML element', function() {
var serialNode = new axe.SerialVirtualNode({
nodeName: 'xx-heading'
});
serialNode.parent = null;

assert.isTrue(rule.matches(null, serialNode));
});

it('returns false when passed an SVG circle element', function() {
var serialNode = new axe.SerialVirtualNode({
nodeName: 'circle'
});
var parent = new axe.SerialVirtualNode({
nodeName: 'svg'
});
serialNode.parent = parent;
parent.children = [serialNode];

assert.isFalse(rule.matches(null, serialNode));
});
});
});

0 comments on commit 18c22fd

Please sign in to comment.