Skip to content

Commit 6ddc4e5

Browse files
author
Marcy Sutton
committed
fix: use virtual methods where applicable
Until we have bi-directional node/vNode APIs it didn't make sense to use virtual methods everywhere
1 parent 9c7b9f1 commit 6ddc4e5

File tree

9 files changed

+80
-69
lines changed

9 files changed

+80
-69
lines changed

lib/checks/keyboard/focusable-no-name.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ var tabIndex = node.getAttribute('tabindex'),
33
if (!inFocusOrder) {
44
return false;
55
}
6-
return !axe.commons.text.accessibleText(node);
6+
return !axe.commons.text.accessibleTextVirtual(virtualNode);

lib/checks/label/implicit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
var label = axe.commons.dom.findUpVirtual(virtualNode, 'label');
33
if (label) {
4-
return !!axe.commons.text.accessibleText(label);
4+
return !!axe.commons.text.accessibleTextVirtual(label);
55
}
66
return false;

lib/checks/shared/button-has-visible-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let role = node.getAttribute('role');
33
let label;
44

55
if (nodeName === 'BUTTON' || (role === 'button' && nodeName !== 'INPUT')) {
6-
label = axe.commons.text.accessibleText(node);
6+
label = axe.commons.text.accessibleTextVirtual(virtualNode);
77
this.data(label);
88

99
return !!label;

lib/checks/shared/has-visible-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
return axe.commons.text.accessibleText(node).length > 0;
1+
return axe.commons.text.accessibleTextVirtual(virtualNode).length > 0;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// passing node.caption to accessibleText instead of using the logic in accessibleTextVirtual on virtualNode
12
return !!(node.summary && node.caption) && node.summary === axe.commons.text.accessibleText(node.caption);

test/checks/keyboard/focusable-no-name.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,51 @@ describe('focusable-no-name', function () {
22
'use strict';
33

44
var fixture = document.getElementById('fixture');
5-
var fixtureSetup = axe.testUtils.fixtureSetup;
5+
var checkSetup = axe.testUtils.checkSetup;
6+
var shadowCheckSetup = axe.testUtils.shadowCheckSetup;
67
var shadowSupport = axe.testUtils.shadowSupport;
78

9+
var checkContext = {
10+
_data: null,
11+
data: function (d) {
12+
this._data = d;
13+
}
14+
};
15+
816
afterEach(function () {
917
fixture.innerHTML = '';
18+
axe._tree = undefined;
1019
});
1120

1221
it('should pass if tabindex < 0', function () {
13-
fixtureSetup('<a href="#" tabindex="-1"></a>');
14-
var node = fixture.querySelector('a');
15-
assert.isFalse(checks['focusable-no-name'].evaluate(node));
22+
var params = checkSetup('<a href="#" tabindex="-1" id="target"></a>');
23+
assert.isFalse(checks['focusable-no-name'].evaluate.apply(checkContext, params));
1624
});
1725

1826
it('should pass element is not natively focusable', function () {
19-
fixtureSetup('<span role="link" href="#"></span>');
20-
var node = fixture.querySelector('span');
21-
assert.isFalse(checks['focusable-no-name'].evaluate(node));
27+
var params = checkSetup('<span role="link" href="#" id="target"></span>');
28+
assert.isFalse(checks['focusable-no-name'].evaluate.apply(checkContext, params));
2229
});
2330

2431
it('should fail if element is tabbable with no name - native', function () {
25-
fixtureSetup('<a href="#"></a>');
26-
var node = fixture.querySelector('a');
27-
assert.isTrue(checks['focusable-no-name'].evaluate(node));
32+
var params = checkSetup('<a href="#" id="target"></a>');
33+
assert.isTrue(checks['focusable-no-name'].evaluate.apply(checkContext, params));
2834
});
2935

30-
it('should fail if element is tabable with no name - ARIA', function () {
31-
fixtureSetup('<span tabindex="0" role="link" href="#"></spam>');
32-
var node = fixture.querySelector('span');
33-
assert.isTrue(checks['focusable-no-name'].evaluate(node));
36+
it('should fail if element is tabbable with no name - ARIA', function () {
37+
var params = checkSetup('<span tabindex="0" role="link" id="target" href="#"></spam>');
38+
assert.isTrue(checks['focusable-no-name'].evaluate.apply(checkContext, params));
3439
});
3540

36-
it('should pass if the element is tabable but has an accessible name', function () {
37-
fixtureSetup('<a href="#" title="Hello"></a>');
38-
var node = fixture.querySelector('a');
39-
assert.isFalse(checks['focusable-no-name'].evaluate(node));
41+
it('should pass if the element is tabbable but has an accessible name', function () {
42+
var params = checkSetup('<a href="#" title="Hello" id="target"></a>');
43+
assert.isFalse(checks['focusable-no-name'].evaluate.apply(checkContext, params));
4044
});
4145

4246
(shadowSupport.v1 ? it : xit)('should pass if the content is passed in with shadow DOM', function () {
43-
var node = document.createElement('div');
44-
node.innerText = 'Content!';
45-
var shadow = node.attachShadow({ mode: 'open' });
46-
shadow.innerHTML = '<a href="#"><slot></slot></a>';
47-
fixtureSetup(node);
48-
49-
var link = shadow.querySelector('a');
50-
assert.isFalse(checks['focusable-no-name'].evaluate(link));
47+
var params = shadowCheckSetup('<div>Content!</div>', '<a href="#" id="target"><slot></slot></a>');
48+
49+
assert.isFalse(checks['focusable-no-name'].evaluate.apply(checkContext, params));
5150
});
5251

5352
});

test/checks/shared/button-has-visible-text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ describe('button-has-visible-text', function () {
2929
});
3030

3131
it('should return true if ARIA button has text', function () {
32-
var checkArgs = checkSetup('<div role="button">Text</div>>', '[role=button]');
32+
var checkArgs = checkSetup('<div role="button">Text</div>', '[role=button]');
3333

3434
assert.isTrue(checks['button-has-visible-text'].evaluate.apply(checkContext, checkArgs));
3535
assert.deepEqual(checkContext._data, 'Text');
3636
});
3737

3838
it('should return false if ARIA button has no text', function () {
39-
var checkArgs = checkSetup('<div role="button"></div>>', '[role=button]');
39+
var checkArgs = checkSetup('<div role="button"></div>', '[role=button]');
4040

4141
assert.isFalse(checks['button-has-visible-text'].evaluate.apply(checkContext, checkArgs));
4242
});

test/checks/shared/has-visible-text.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,34 @@ describe('has-visible-text', function () {
22
'use strict';
33

44
var fixture = document.getElementById('fixture');
5-
var fixtureSetup = axe.testUtils.fixtureSetup;
5+
var checkSetup = axe.testUtils.checkSetup;
6+
7+
var checkContext = {
8+
_data: null,
9+
data: function (d) {
10+
this._data = d;
11+
}
12+
};
613

714
afterEach(function () {
815
fixture.innerHTML = '';
16+
axe._tree = undefined;
17+
checkContext._data = null;
918
});
1019

1120
it('should return false if there is no visible text', function () {
12-
fixtureSetup('<object></object>');
13-
var node = document.querySelector('object');
14-
assert.isFalse(checks['has-visible-text'].evaluate(node));
21+
var params = checkSetup('<object id="target"></object>');
22+
assert.isFalse(checks['has-visible-text'].evaluate.apply(checkContext, params));
1523
});
1624

1725
it('should return false if there is text, but its hidden', function () {
18-
fixtureSetup('<object><span style="display:none">hello!</span></object>');
19-
var node = document.querySelector('object');
20-
assert.isFalse(checks['has-visible-text'].evaluate(node));
26+
var params = checkSetup('<object id="target"><span style="display:none">hello!</span></object>');
27+
assert.isFalse(checks['has-visible-text'].evaluate.apply(checkContext, params));
2128
});
2229

2330
it('should return true if there is visible text', function () {
24-
fixtureSetup('<object>hello!</object>');
25-
var node = document.querySelector('object');
26-
assert.isTrue(checks['has-visible-text'].evaluate(node));
31+
var params = checkSetup('<object id="target">hello!</object>');
32+
assert.isTrue(checks['has-visible-text'].evaluate.apply(checkContext, params));
2733
});
2834

2935
});

test/checks/tables/same-caption-summary.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,64 @@ describe('same-caption-summary', function () {
22
'use strict';
33

44
var fixture = document.getElementById('fixture');
5-
var fixtureSetup = axe.testUtils.fixtureSetup;
5+
var checkSetup = axe.testUtils.checkSetup;
6+
var shadowCheckSetup = axe.testUtils.shadowCheckSetup;
67
var shadowSupport = axe.testUtils.shadowSupport;
78

9+
var checkContext = {
10+
_data: null,
11+
data: function (d) {
12+
this._data = d;
13+
}
14+
};
15+
16+
817
afterEach(function () {
918
fixture.innerHTML = '';
19+
axe._tree = undefined;
1020
});
1121

1222
it('should return false there is no caption', function () {
13-
fixtureSetup('<table summary="hi"><tr><td></td></tr></table>');
14-
var node = fixture.querySelector('table');
23+
var params = checkSetup('<table summary="hi" id="target"><tr><td></td></tr></table>');
1524

16-
assert.isFalse(checks['same-caption-summary'].evaluate(node));
25+
assert.isFalse(checks['same-caption-summary'].evaluate.apply(checkContext, params));
1726

1827
});
1928

2029
it('should return false there is no summary', function () {
21-
fixtureSetup('<table><caption>Hi</caption><tr><td></td></tr></table>');
22-
var node = fixture.querySelector('table');
30+
var params = checkSetup('<table id="target"><caption>Hi</caption><tr><td></td></tr></table>');
2331

24-
assert.isFalse(checks['same-caption-summary'].evaluate(node));
32+
assert.isFalse(checks['same-caption-summary'].evaluate.apply(checkContext, params));
2533

2634
});
2735

2836
it('should return false if summary and caption are different', function () {
29-
fixtureSetup('<table summary="bye"><caption>Hi</caption><tr><td></td></tr></table>');
30-
var node = fixture.querySelector('table');
37+
var params = checkSetup('<table summary="bye" id="target"><caption>Hi</caption><tr><td></td></tr></table>');
3138

32-
assert.isFalse(checks['same-caption-summary'].evaluate(node));
39+
assert.isFalse(checks['same-caption-summary'].evaluate.apply(checkContext, params));
3340

3441
});
3542

3643
it('should return true if summary and caption are the same', function () {
37-
fixtureSetup('<table summary="Hi"><caption>Hi</caption><tr><td></td></tr></table>');
38-
var node = fixture.querySelector('table');
44+
var params = checkSetup('<table summary="Hi" id="target"><caption>Hi</caption><tr><td></td></tr></table>');
3945

40-
assert.isTrue(checks['same-caption-summary'].evaluate(node));
46+
assert.isTrue(checks['same-caption-summary'].evaluate.apply(checkContext, params));
4147
});
4248

4349
(shadowSupport.v1 ? it : xit)('should match slotted caption elements', function () {
44-
var node = document.createElement('div');
45-
node.innerHTML = '<span slot="caption">Caption</span>' +
46-
'<span slot="one">Data element 1</span>' +
47-
'<span slot="two">Data element 2</span>';
48-
49-
var root = node.attachShadow({ mode: 'open' });
50-
var table = document.createElement('table');
51-
table.innerHTML = '<caption><slot name="caption"></slot></caption>' +
52-
'<tr><td><slot name="one"></slot></td><td><slot name="two"></slot></td></tr>';
53-
table.setAttribute('summary', 'Caption');
54-
root.appendChild(table);
55-
fixtureSetup(node);
56-
57-
assert.isTrue(checks['same-caption-summary'].evaluate(table));
50+
var params = shadowCheckSetup(
51+
'<div>' +
52+
'<span slot="caption">Caption</span>' +
53+
'<span slot="one">Data element 1</span>' +
54+
'<span slot="two">Data element 2</span>' +
55+
'</div>',
56+
'<table summary="Caption" id="target">' +
57+
'<caption><slot name="caption"></slot></caption>' +
58+
'<tr><td><slot name="one"></slot></td><td><slot name="two"></slot></td></tr>' +
59+
'</table>'
60+
);
61+
62+
assert.isTrue(checks['same-caption-summary'].evaluate.apply(checkContext, params));
5863
});
5964

6065
});

0 commit comments

Comments
 (0)