diff --git a/lib/checks/aria/invalidrole.js b/lib/checks/aria/invalidrole.js index c44ce05ce9..b7a180f8ba 100644 --- a/lib/checks/aria/invalidrole.js +++ b/lib/checks/aria/invalidrole.js @@ -1,13 +1,16 @@ -const invalidRoles = axe.utils - .tokenList(virtualNode.attr('role')) - .filter(role => { - return !axe.commons.aria.isValidRole(role, { - allowAbstract: true - }); - }); +const { tokenList } = axe.utils; +const { aria } = axe.commons; -if (invalidRoles.length > 0) { - this.data(invalidRoles); +const allRoles = tokenList(virtualNode.attr('role')); +const allInvalid = allRoles.every( + role => !aria.isValidRole(role, { allowAbstract: true }) +); + +/** + * Only fail when all the roles are invalid + */ +if (allInvalid) { + this.data(allRoles); return true; } diff --git a/test/checks/shared/invalidrole.js b/test/checks/shared/invalidrole.js index e396dd1677..6e5d49c61a 100644 --- a/test/checks/shared/invalidrole.js +++ b/test/checks/shared/invalidrole.js @@ -83,10 +83,24 @@ describe('invalidrole', function() { assert.isNull(checkContext._data); }); - it('should return true if applied to at least one nonsensical role', function() { + it('should return false if atleast one role is valid', function() { var virtualNode = queryFixture( '