Skip to content

Commit c7489ab

Browse files
authored
fix(th-has-data-cells): empty cells will now pass (#1659)
* fix(th-has-data-cells): empty cells will now pass * filter headers * fix test * find instead of filter * move test to passes
1 parent c64bd02 commit c7489ab

File tree

6 files changed

+20
-25
lines changed

6 files changed

+20
-25
lines changed

lib/checks/tables/th-has-data-cells.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,19 @@ headers.forEach(header => {
4040

4141
const pos = tableUtils.getCellPosition(header, tableGrid);
4242

43-
// look for any column cell that has content and is not a column header
43+
// ensure column header has at least 1 non-header cell
4444
let hasCell = false;
4545
if (tableUtils.isColumnHeader(header)) {
4646
hasCell = tableUtils
4747
.traverse('down', pos, tableGrid)
48-
.some(
49-
cell =>
50-
axe.commons.dom.hasContent(cell) && !tableUtils.isColumnHeader(cell)
51-
);
48+
.find(cell => !tableUtils.isColumnHeader(cell));
5249
}
5350

54-
// look for any row cell that has content and is not a row header
51+
// ensure row header has at least 1 non-header cell
5552
if (!hasCell && tableUtils.isRowHeader(header)) {
5653
hasCell = tableUtils
5754
.traverse('right', pos, tableGrid)
58-
.some(
59-
cell =>
60-
axe.commons.dom.hasContent(cell) && !tableUtils.isRowHeader(cell)
61-
);
55+
.find(cell => !tableUtils.isRowHeader(cell));
6256
}
6357

6458
// report the node as having failed

test/checks/tables/th-has-data-cells.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('th-has-data-cells', function() {
112112
);
113113
});
114114

115-
it('should return undefined if all data cells are empty', function() {
115+
it('should return true if all data cells are empty', function() {
116116
fixture.innerHTML =
117117
'<table>' +
118118
' <tr> <th>hi</th> <td></td> </tr>' +
@@ -121,7 +121,7 @@ describe('th-has-data-cells', function() {
121121

122122
axe.testUtils.flatTreeSetup(fixture);
123123
var node = fixture.querySelector('table');
124-
assert.isUndefined(
124+
assert.isTrue(
125125
checks['th-has-data-cells'].evaluate.call(checkContext, node)
126126
);
127127
});

test/integration/full/incomplete/th-has-data-cells.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@
3030
</tr>
3131
</table>
3232

33-
<table id="table2">
34-
<tr>
35-
<th>hi</th>
36-
<td></td>
37-
</tr>
38-
<tr>
39-
<th>hi</th>
40-
<td></td>
41-
</tr>
42-
</table>
43-
4433
<table id="table3">
4534
<tr>
4635
<td>axe</td>

test/integration/full/incomplete/th-has-data-cells.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('th-has-data-cells cantTell test', function() {
2929
describe('incomplete data', function() {
3030
it('should be incomplete for missing or empty data cells', function() {
3131
var resultNodes = results.incomplete[0].nodes;
32-
assert.lengthOf(resultNodes, 3);
32+
assert.lengthOf(resultNodes, 2);
3333
resultNodes[0].any.forEach(function(check) {
3434
assert.match(check.message, 'Table data cells are missing or empty');
3535
});

test/integration/rules/th-has-data-cells/th-has-data-cells.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@
6161
</tr>
6262
</table>
6363

64+
<table id="pass8">
65+
<tr>
66+
<th>hi</th>
67+
<td></td>
68+
</tr>
69+
<tr>
70+
<th>hi</th>
71+
<td></td>
72+
</tr>
73+
</table>
74+
6475
<table id="canttell1">
6576
<tr>
6677
<td>axe</td>

test/integration/rules/th-has-data-cells/th-has-data-cells.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
["#pass4"],
1515
["#pass5"],
1616
["#pass6"],
17-
["#pass7"]
17+
["#pass7"],
18+
["#pass8"]
1819
]
1920
}

0 commit comments

Comments
 (0)