From 87cfc0b4f4d998a88a2d534438e4f2ccf9427a86 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Tue, 3 Aug 2021 09:14:18 -0600 Subject: [PATCH] feat(aria-allowed-attr): report violations for non-global ARIA attributes on elements without a role (#3102) * feat(aria-allowed-attr): report violations for non-global ARIA attributes on elements without a role * fix tests * remove wrong test --- lib/checks/aria/aria-allowed-attr-evaluate.js | 2 +- test/checks/aria/allowed-attr.js | 17 +++++++++++++++-- .../rules/aria-allowed-attr/failures.html | 6 ++++++ .../rules/aria-allowed-attr/failures.json | 3 ++- .../virtual-rules/aria-allowed-attr.js | 17 +++++++++++++++-- .../virtual-rules/aria-allowed-role.js | 13 ------------- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/checks/aria/aria-allowed-attr-evaluate.js b/lib/checks/aria/aria-allowed-attr-evaluate.js index 59da14c22a..19775a9528 100644 --- a/lib/checks/aria/aria-allowed-attr-evaluate.js +++ b/lib/checks/aria/aria-allowed-attr-evaluate.js @@ -38,7 +38,7 @@ function ariaAllowedAttrEvaluate(node, options, virtualNode) { allowed = uniqueArray(options[role].concat(allowed)); } - if (role && allowed) { + if (allowed) { for (let i = 0; i < attrs.length; i++) { const attrName = attrs[i]; if (validateAttr(attrName) && !allowed.includes(attrName)) { diff --git a/test/checks/aria/allowed-attr.js b/test/checks/aria/allowed-attr.js index cbba61b843..e63e64bbb9 100644 --- a/test/checks/aria/allowed-attr.js +++ b/test/checks/aria/allowed-attr.js @@ -46,9 +46,9 @@ describe('aria-allowed-attr', function() { assert.deepEqual(checkContext._data, ['aria-selected="true"']); }); - it('should return true if there is no role', function() { + it('should return true for global attributes if there is no role', function() { var vNode = queryFixture( - '
' + '' ); assert.isTrue( @@ -59,6 +59,19 @@ describe('aria-allowed-attr', function() { assert.isNull(checkContext._data); }); + it('should return false for non-global attributes if there is no role', function() { + var vNode = queryFixture( + '' + ); + + assert.isFalse( + axe.testUtils + .getCheckEvaluate('aria-allowed-attr') + .call(checkContext, null, null, vNode) + ); + assert.deepEqual(checkContext._data, ['aria-selected="true"']); + }); + it('should not report on invalid attributes', function() { var vNode = queryFixture( '' diff --git a/test/integration/rules/aria-allowed-attr/failures.html b/test/integration/rules/aria-allowed-attr/failures.html index f4839431e7..0f77954a3f 100644 --- a/test/integration/rules/aria-allowed-attr/failures.html +++ b/test/integration/rules/aria-allowed-attr/failures.html @@ -28,3 +28,9 @@