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

Make explicit check consider shadow DOM #442

Merged
merged 2 commits into from
Jul 17, 2017
Merged
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
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));
});

});