From b595b421f296b1355c27cbd90347e5c1ddbd9fd3 Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Fri, 7 Jul 2017 14:34:03 -0700 Subject: [PATCH] feat: add SD support to color-contrast-matches --- lib/rules/color-contrast-matches.js | 2 +- test/rule-matches/color-contrast-matches.js | 22 ++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/rules/color-contrast-matches.js b/lib/rules/color-contrast-matches.js index 9622773fb4..053b78fc14 100644 --- a/lib/rules/color-contrast-matches.js +++ b/lib/rules/color-contrast-matches.js @@ -61,7 +61,7 @@ if (node.id) { } } -if (axe.commons.text.visible(node, false, true) === '') { +if (axe.commons.text.visible(virtualNode, false, true) === '') { return false; } diff --git a/test/rule-matches/color-contrast-matches.js b/test/rule-matches/color-contrast-matches.js index 307cd717cd..0a485a6b67 100644 --- a/test/rule-matches/color-contrast-matches.js +++ b/test/rule-matches/color-contrast-matches.js @@ -12,6 +12,7 @@ describe('color-contrast-matches', function () { afterEach(function () { fixture.innerHTML = ''; + axe._tree = undefined; }); it('is a function', function () { @@ -22,42 +23,48 @@ describe('color-contrast-matches', function () { fixture.innerHTML = '
' + '
'; var target = fixture.querySelector('#target'); - assert.isFalse(rule.matches(target)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target))); }); it('should match when there is text', function () { fixture.innerHTML = '
' + 'My text
'; var target = fixture.querySelector('#target'); - assert.isTrue(rule.matches(target)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target))); }); it('should not match when there is text that is out of the container', function () { fixture.innerHTML = '
' + 'My text
'; var target = fixture.querySelector('#target'); - assert.isFalse(rule.matches(target)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target))); }); it('should not match when there is text that is out of the container with overflow hidden', function () { fixture.innerHTML = '
' + 'text
'; var target = fixture.querySelector('#target'); - assert.isFalse(rule.matches(target)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target))); }); it('should match when there is text that is in the scroll reach of container', function () { fixture.innerHTML = '
' + 'text
'; var target = fixture.querySelector('#target'); - assert.isTrue(rule.matches(target)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target))); }); it('should match when there is text that is only partially out of the container', function () { fixture.innerHTML = '
' + 'My text
'; var target = fixture.querySelector('#target'); - assert.isTrue(rule.matches(target)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target))); }); it('should match ', function () { @@ -148,7 +155,8 @@ describe('color-contrast-matches', function () { it('should match '; var target = fixture.querySelector('button'); - assert.isTrue(rule.matches(target)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target))); }); it('should not match