From 2467b3a59cb853689b88a15580acd6e9b210dd6b Mon Sep 17 00:00:00 2001 From: Dan Tripp Date: Thu, 19 Aug 2021 21:12:04 -0400 Subject: [PATCH] refactor(checks/navigation): improve `internal-link-present-evaluate` Make `internal-link-present-evaluate` work with virtualNode rather than actualNode. Closes issue #2466 --- .../internal-link-present-evaluate.js | 20 +-- .../navigation/internal-link-present.js | 155 +++++++++--------- 2 files changed, 88 insertions(+), 87 deletions(-) diff --git a/lib/checks/navigation/internal-link-present-evaluate.js b/lib/checks/navigation/internal-link-present-evaluate.js index acf086d43f..d235bfbe2b 100644 --- a/lib/checks/navigation/internal-link-present-evaluate.js +++ b/lib/checks/navigation/internal-link-present-evaluate.js @@ -1,10 +1,10 @@ -import { querySelectorAll } from '../../core/utils'; - -function internalLinkPresentEvaluate(node, options, virtualNode) { - const links = querySelectorAll(virtualNode, 'a[href]'); - return links.some(vLink => { - return /^#[^/!]/.test(vLink.actualNode.getAttribute('href')); - }); -} - -export default internalLinkPresentEvaluate; +import { querySelectorAll } from '../../core/utils'; + +function internalLinkPresentEvaluate(node, options, virtualNode) { + const links = querySelectorAll(virtualNode, 'a[href]'); + return links.some(vLink => { + return /^#[^/!]/.test(vLink.attr('href')); + }); +} + +export default internalLinkPresentEvaluate; diff --git a/test/checks/navigation/internal-link-present.js b/test/checks/navigation/internal-link-present.js index 5ea7efed12..2f3d34d561 100644 --- a/test/checks/navigation/internal-link-present.js +++ b/test/checks/navigation/internal-link-present.js @@ -1,77 +1,78 @@ -describe('internal-link-present', function() { - 'use strict'; - - var fixture = document.getElementById('fixture'); - var shadowSupported = axe.testUtils.shadowSupport.v1; - var checkContext = axe.testUtils.MockCheckContext(); - var checkSetup = axe.testUtils.checkSetup; - var shadowCheckSetup = axe.testUtils.shadowCheckSetup; - - afterEach(function() { - fixture.innerHTML = ''; - axe._tree = undefined; - checkContext.reset(); - }); - - it('should return true when an internal link is found', function() { - var params = checkSetup('
hi
'); - assert.isTrue( - axe.testUtils - .getCheckEvaluate('internal-link-present') - .apply(checkContext, params) - ); - }); - - it('should return false when a hashbang URL was used', function() { - var params = checkSetup('
hi
'); - assert.isFalse( - axe.testUtils - .getCheckEvaluate('internal-link-present') - .apply(checkContext, params) - ); - }); - - it('should return false when a hash route URL was used', function() { - var params = checkSetup('
hi
'); - assert.isFalse( - axe.testUtils - .getCheckEvaluate('internal-link-present') - .apply(checkContext, params) - ); - }); - - it('should return false when a hashbang + slash route URL was used', function() { - var params = checkSetup('
hi
'); - assert.isFalse( - axe.testUtils - .getCheckEvaluate('internal-link-present') - .apply(checkContext, params) - ); - }); - - it('should otherwise return false', function() { - var params = checkSetup( - '
hi
' - ); - assert.isFalse( - axe.testUtils - .getCheckEvaluate('internal-link-present') - .apply(checkContext, params) - ); - }); - - (shadowSupported ? it : xit)( - 'should return true when internal link is found in shadow dom', - function() { - var params = shadowCheckSetup( - '
', - 'hi' - ); - assert.isTrue( - axe.testUtils - .getCheckEvaluate('internal-link-present') - .apply(checkContext, params) - ); - } - ); -}); +describe('internal-link-present', function() { + 'use strict'; + + var fixture = document.getElementById('fixture'); + var shadowSupported = axe.testUtils.shadowSupport.v1; + var checkContext = axe.testUtils.MockCheckContext(); + var shadowCheckSetup = axe.testUtils.shadowCheckSetup; + var queryFixture = axe.testUtils.queryFixture; + + afterEach(function() { + fixture.innerHTML = ''; + axe._tree = undefined; + checkContext.reset(); + }); + + it('should return true when an internal link is found', function() { + var vNode = queryFixture('
hi
'); + assert.isTrue( + axe.testUtils + .getCheckEvaluate('internal-link-present') + .call(checkContext, null, {}, vNode) + ); + }); + + it('should return false when a hashbang URL was used', function() { + var vNode = queryFixture('
hi
'); + assert.isFalse( + axe.testUtils + .getCheckEvaluate('internal-link-present') + .call(checkContext, null, {}, vNode) + ); + }); + + it('should return false when a hash route URL was used', function() { + var vNode = queryFixture('
hi
'); + assert.isFalse( + axe.testUtils + .getCheckEvaluate('internal-link-present') + .call(checkContext, null, {}, vNode) + ); + }); + + it('should return false when a hashbang + slash route URL was used', function() { + var vNode = queryFixture('
hi
'); + assert.isFalse( + axe.testUtils + .getCheckEvaluate('internal-link-present') + .call(checkContext, null, {}, vNode) + ); + }); + + it('should otherwise return false', function() { + var vNode = queryFixture( + '
hi
' + ); + assert.isFalse( + axe.testUtils + .getCheckEvaluate('internal-link-present') + .call(checkContext, null, {}, vNode) + ); + }); + + (shadowSupported ? it : xit)( + 'should return true when internal link is found in shadow dom', + function() { + var params = shadowCheckSetup( + '
', + 'hi' + ); + var vNode = params[2]; + assert.isTrue( + axe.testUtils + .getCheckEvaluate('internal-link-present') + .call(checkContext, null, {}, vNode) + ); + } + ); +});