Skip to content

Commit b595b42

Browse files
author
Marcy Sutton
committed
feat: add SD support to color-contrast-matches
1 parent 85deffa commit b595b42

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/rules/color-contrast-matches.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if (node.id) {
6161
}
6262
}
6363

64-
if (axe.commons.text.visible(node, false, true) === '') {
64+
if (axe.commons.text.visible(virtualNode, false, true) === '') {
6565
return false;
6666
}
6767

test/rule-matches/color-contrast-matches.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('color-contrast-matches', function () {
1212

1313
afterEach(function () {
1414
fixture.innerHTML = '';
15+
axe._tree = undefined;
1516
});
1617

1718
it('is a function', function () {
@@ -22,42 +23,48 @@ describe('color-contrast-matches', function () {
2223
fixture.innerHTML = '<div style="color: yellow; background-color: white;" id="target">' +
2324
' </div>';
2425
var target = fixture.querySelector('#target');
25-
assert.isFalse(rule.matches(target));
26+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
27+
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target)));
2628
});
2729

2830
it('should match when there is text', function () {
2931
fixture.innerHTML = '<div style="color: yellow; background-color: white;" id="target">' +
3032
'My text</div>';
3133
var target = fixture.querySelector('#target');
32-
assert.isTrue(rule.matches(target));
34+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
35+
assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target)));
3336
});
3437

3538
it('should not match when there is text that is out of the container', function () {
3639
fixture.innerHTML = '<div style="color: yellow; text-indent: -9999px; background-color: white;" id="target">' +
3740
'My text</div>';
3841
var target = fixture.querySelector('#target');
39-
assert.isFalse(rule.matches(target));
42+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
43+
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target)));
4044
});
4145

4246
it('should not match when there is text that is out of the container with overflow hidden', function () {
4347
fixture.innerHTML = '<div style="color: yellow; width: 100px; overflow: hidden; text-indent: 200px; background-color: white;" id="target">' +
4448
'text</div>';
4549
var target = fixture.querySelector('#target');
46-
assert.isFalse(rule.matches(target));
50+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
51+
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target)));
4752
});
4853

4954
it('should match when there is text that is in the scroll reach of container', function () {
5055
fixture.innerHTML = '<div style="color: yellow; width: 100px; overflow: scroll; text-indent: 200px; background-color: white;" id="target">' +
5156
'text</div>';
5257
var target = fixture.querySelector('#target');
53-
assert.isTrue(rule.matches(target));
58+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
59+
assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target)));
5460
});
5561

5662
it('should match when there is text that is only partially out of the container', function () {
5763
fixture.innerHTML = '<div style="color: yellow; text-indent: -20px; background-color: white;" id="target">' +
5864
'My text</div>';
5965
var target = fixture.querySelector('#target');
60-
assert.isTrue(rule.matches(target));
66+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
67+
assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target)));
6168
});
6269

6370
it('should match <input type="text">', function () {
@@ -148,7 +155,8 @@ describe('color-contrast-matches', function () {
148155
it('should match <button>', function () {
149156
fixture.innerHTML = '<button>hi</button>';
150157
var target = fixture.querySelector('button');
151-
assert.isTrue(rule.matches(target));
158+
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
159+
assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target)));
152160
});
153161

154162
it('should not match <button disabled>', function () {

0 commit comments

Comments
 (0)