From e67fc655db2bbc4708e2a41a1b592cb27f12459f Mon Sep 17 00:00:00 2001 From: Jey Date: Tue, 27 Nov 2018 18:42:29 +0530 Subject: [PATCH] fix: handle noscript and template in dom.isVisible (#1257) --- lib/commons/dom/is-visible.js | 5 ++--- test/commons/dom/is-visible.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/commons/dom/is-visible.js b/lib/commons/dom/is-visible.js index e89dc1bce9..1b92751f98 100644 --- a/lib/commons/dom/is-visible.js +++ b/lib/commons/dom/is-visible.js @@ -1,5 +1,5 @@ /* global dom */ -/* eslint complexity: ["error", 18] */ +/* eslint complexity: ["error", 20] */ /** * Determines if an element is hidden with the clip rect technique @@ -56,8 +56,7 @@ dom.isVisible = function(el, screenReader, recursed) { if ( style.getPropertyValue('display') === 'none' || - nodeName.toUpperCase() === 'STYLE' || - nodeName.toUpperCase() === 'SCRIPT' || + ['STYLE', 'SCRIPT', 'NOSCRIPT', 'TEMPLATE'].includes(nodeName) || (!screenReader && isClipped(style.getPropertyValue('clip'))) || (!recursed && // visibility is only accurate on the first element diff --git a/test/commons/dom/is-visible.js b/test/commons/dom/is-visible.js index 80bcd1bd6c..8f29b1ae55 100644 --- a/test/commons/dom/is-visible.js +++ b/test/commons/dom/is-visible.js @@ -1,6 +1,8 @@ describe('dom.isVisible', function() { 'use strict'; + var fixture = document.getElementById('fixture'); + var fixtureSetup = axe.testUtils.fixtureSetup; var shadowSupported = axe.testUtils.shadowSupport.v1; var fakeNode = { nodeType: Node.ELEMENT_NODE, @@ -78,6 +80,33 @@ describe('dom.isVisible', function() { assert.isTrue(axe.commons.dom.isVisible(document)); }); + it('should return false on STYLE tag', function() { + var fixture = fixtureSetup( + '' + ); + var node = fixture.querySelector('#target'); + var actual = axe.commons.dom.isVisible(node); + assert.isFalse(actual); + }); + + it('should return false on NOSCRIPT tag', function() { + var fixture = fixtureSetup( + '' + ); + var node = fixture.querySelector('#target'); + var actual = axe.commons.dom.isVisible(node); + assert.isFalse(actual); + }); + + it('should return false on TEMPLATE tag', function() { + var fixture = fixtureSetup( + '' + ); + var node = fixture.querySelector('#target'); + var actual = axe.commons.dom.isVisible(node); + assert.isFalse(actual); + }); + it('should return true if positioned staticly but top/left is set', function() { fixture.innerHTML = '