diff --git a/lib/rules/color-contrast-matches.js b/lib/rules/color-contrast-matches.js index b1f1e6ee54..c38e44fe48 100644 --- a/lib/rules/color-contrast-matches.js +++ b/lib/rules/color-contrast-matches.js @@ -93,7 +93,15 @@ if (node.getAttribute('id')) { } } -if (axe.commons.text.visibleVirtual(virtualNode, false, true) === '') { +const visibleText = axe.commons.text.visibleVirtual(virtualNode, false, true); +if ( + visibleText === '' || + axe.commons.text.removeUnicode(visibleText, { + emoji: true, + nonBmp: true, + punctuations: true + }) === '' +) { return false; } diff --git a/test/rule-matches/color-contrast-matches.js b/test/rule-matches/color-contrast-matches.js index addff93661..c0763e0485 100644 --- a/test/rule-matches/color-contrast-matches.js +++ b/test/rule-matches/color-contrast-matches.js @@ -39,6 +39,33 @@ describe('color-contrast-matches', function() { assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(target))); }); + it('should not match when text only contains emoji', function() { + fixture.innerHTML = + '
' + + '🌎
'; + var target = fixture.querySelector('#target'); + axe.testUtils.flatTreeSetup(fixture); + assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target))); + }); + + it('should not match when text only contains punctuation', function() { + fixture.innerHTML = + '
' + + '‏
'; + var target = fixture.querySelector('#target'); + axe.testUtils.flatTreeSetup(fixture); + assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target))); + }); + + it('should not match when text only contains nonBmp unicode', function() { + fixture.innerHTML = + '
' + + 'â—“
'; + var target = fixture.querySelector('#target'); + axe.testUtils.flatTreeSetup(fixture); + assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target))); + }); + it('should not match when there is text that is out of the container', function() { fixture.innerHTML = '
' +