diff --git a/lib/commons/aria/get-role.js b/lib/commons/aria/get-role.js index 7f6d6556ae..fb5fc7347f 100644 --- a/lib/commons/aria/get-role.js +++ b/lib/commons/aria/get-role.js @@ -54,6 +54,10 @@ function getInheritedRole(vNode, explicitRoleOptions) { // if we can't look at the parent then we can't know if the node // inherits the presentational role or not if (!vNode.parent) { + if (!vNode.actualNode) { + return null; + } + throw new ReferenceError( 'Cannot determine role presentational inheritance of a required parent outside the current scope.' ); diff --git a/lib/rules/empty-table-header.json b/lib/rules/empty-table-header.json index 5989478377..49ff72909e 100644 --- a/lib/rules/empty-table-header.json +++ b/lib/rules/empty-table-header.json @@ -1,6 +1,6 @@ { "id": "empty-table-header", - "selector": "th, [role=\"rowheader\"], [role=\"columnheader\"]", + "selector": "th:not([role]), [role=\"rowheader\"], [role=\"columnheader\"]", "tags": ["cat.name-role-value", "best-practice"], "metadata": { "description": "Ensures table headers have discernible text", diff --git a/test/commons/aria/get-role.js b/test/commons/aria/get-role.js index f0436fe9a0..340c90a88b 100644 --- a/test/commons/aria/get-role.js +++ b/test/commons/aria/get-role.js @@ -412,4 +412,26 @@ describe('aria.getRole', function () { assert.isNull(aria.getRole(node, { noPresentational: true })); }); }); + + describe('SerialVirtualNode', function () { + it('works with the SerialVirtualNode', function () { + var vNode = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'button' + } + }); + assert.equal(aria.getRole(vNode), 'button'); + }); + + it('does not throw for missing parent in presentational role inheritance', function () { + var vNode = new axe.SerialVirtualNode({ + nodeName: 'li' + }); + + assert.doesNotThrow(function () { + assert.equal(aria.getRole(vNode), 'listitem'); + }); + }); + }); }); diff --git a/test/integration/rules/empty-table-header/empty-table-header.html b/test/integration/rules/empty-table-header/empty-table-header.html index 24b7200d88..bcdb11e18e 100644 --- a/test/integration/rules/empty-table-header/empty-table-header.html +++ b/test/integration/rules/empty-table-header/empty-table-header.html @@ -45,5 +45,11 @@ + +
rowheader with a role | +
---|