-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore empty, whitespace or undefined
role
for rule `ari… (#2077)
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
if (!virtualNode.hasAttr('role')) { | ||
return false; | ||
} | ||
|
||
if (!virtualNode.attr('role').trim()) { | ||
return false; | ||
} | ||
|
||
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
describe('no-role-empty-matches', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
var rule; | ||
|
||
beforeEach(function() { | ||
rule = axe._audit.rules.find(function(rule) { | ||
return rule.id === 'aria-roles'; | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('returns false when element does not have `role` attribute', function() { | ||
var vNode = queryFixture('<div id="target">Some Content</div>'); | ||
var actual = rule.matches(vNode.actualNode, vNode); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns false when element has role attribute has no value', function() { | ||
var vNode = queryFixture('<div role id="target">Some Content</div>'); | ||
var actual = rule.matches(vNode.actualNode, vNode); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns false when element has empty role attribute', function() { | ||
var vNode = queryFixture('<div role="" id="target">Some Content</div>'); | ||
var actual = rule.matches(vNode.actualNode, vNode); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns false when element has role attribute consisting of only whitespace', function() { | ||
var vNode = queryFixture('<div role=" " id="target">Some Content</div>'); | ||
var actual = rule.matches(vNode.actualNode, vNode); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns true when element has role attribute', function() { | ||
var vNode = queryFixture( | ||
'<div role="button" id="target">Some Content</div>' | ||
); | ||
var actual = rule.matches(vNode.actualNode, vNode); | ||
assert.isTrue(actual); | ||
}); | ||
|
||
it('returns true when element has multiple roles', function() { | ||
var vNode = queryFixture( | ||
'<div role="button link" id="target">Some Content</div>' | ||
); | ||
var actual = rule.matches(vNode.actualNode, vNode); | ||
assert.isTrue(actual); | ||
}); | ||
|
||
it('returns true when element has invalid role', function() { | ||
var vNode = queryFixture('<div role="xyz" id="target">Some Content</div>'); | ||
var actual = rule.matches(vNode.actualNode, vNode); | ||
assert.isTrue(actual); | ||
}); | ||
}); |