Skip to content

Commit

Permalink
feat: Make explicit check consider shadow DOM (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored Jul 17, 2017
1 parent ebe1858 commit 9ddfc0f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/checks/label/explicit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ describe('explicit-label', function () {

var fixture = document.getElementById('fixture');
var fixtureSetup = axe.testUtils.fixtureSetup;
var shadowSupport = axe.testUtils.shadowSupport;

afterEach(function () {
fixture.innerHTML = '';
Expand Down Expand Up @@ -34,4 +35,47 @@ describe('explicit-label', function () {
assert.isFalse(checks['explicit-label'].evaluate(node));
});

(shadowSupport.v1 ? it : xit)('should return true if input and label are in the same shadow root', function () {
var root = document.createElement('div');
var shadow = root.attachShadow({ mode: 'open' });
shadow.innerHTML = '<label for="target">American band</label><input id="target">';
fixtureSetup(root);

var node = shadow.querySelector('#target');
assert.isTrue(checks['explicit-label'].evaluate(node));
});

(shadowSupport.v1 ? it : xit)('should return true if label content is slotted', function () {
var root = document.createElement('div');
root.innerHTML = 'American band';
var shadow = root.attachShadow({ mode: 'open' });
shadow.innerHTML = '<label for="target"><slot></slot></label><input id="target">';
fixtureSetup(root);

var node = shadow.querySelector('#target');
assert.isTrue(checks['explicit-label'].evaluate(node));
});

(shadowSupport.v1 ? it : xit)('should return false if input is inside shadow DOM and the label is not', function () {
var root = document.createElement('div');
root.innerHTML = '<label for="target">American band</label>';
var shadow = root.attachShadow({ mode: 'open' });
shadow.innerHTML = '<slot></slot><input id="target">';
fixtureSetup(root);

var node = shadow.querySelector('#target');
assert.isFalse(checks['explicit-label'].evaluate(node));
});

(shadowSupport.v1 ? it : xit)('should return false if label is inside shadow DOM and the input is not', function () {
var root = document.createElement('div');
root.innerHTML = '<input id="target">';
var shadow = root.attachShadow({ mode: 'open' });
shadow.innerHTML = '<label for="target">American band</label><slot></slot>';
fixtureSetup(root);

var node = root.querySelector('#target');
assert.isFalse(checks['explicit-label'].evaluate(node));
});

});

0 comments on commit 9ddfc0f

Please sign in to comment.