From 414dfb1c9a4ade645ce60e8918e8143fe58b3eb6 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Wed, 29 Jan 2020 10:39:00 -0700 Subject: [PATCH] fix(page-no-duplicate-main): do not fail for duplicate hidden elements (#2000) --- lib/checks/keyboard/page-no-duplicate.js | 2 +- test/checks/keyboard/page-no-duplicate.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checks/keyboard/page-no-duplicate.js b/lib/checks/keyboard/page-no-duplicate.js index 7932656249..88322abf32 100644 --- a/lib/checks/keyboard/page-no-duplicate.js +++ b/lib/checks/keyboard/page-no-duplicate.js @@ -15,7 +15,7 @@ axe._cache.set(key, true); let elms = axe.utils.querySelectorAllFilter( axe._tree[0], options.selector, - elm => elm !== virtualNode + elm => elm !== virtualNode && axe.commons.dom.isVisible(elm.actualNode) ); // Filter elements that, within certain contexts, don't map their role. diff --git a/test/checks/keyboard/page-no-duplicate.js b/test/checks/keyboard/page-no-duplicate.js index ea454e4a4d..d1d3ccb1bb 100644 --- a/test/checks/keyboard/page-no-duplicate.js +++ b/test/checks/keyboard/page-no-duplicate.js @@ -50,6 +50,15 @@ describe('page-no-duplicate', function() { assert.isTrue(check.evaluate.apply(checkContext, params)); }); + it('should return true if there is more than one element matching the selector but only one is visible', function() { + var options = { selector: 'main' }; + var params = checkSetup( + '
', + options + ); + assert.isTrue(check.evaluate.apply(checkContext, params)); + }); + (shadowSupported ? it : xit)( 'should return false if there is a second matching element inside the shadow dom', function() {