Skip to content

Commit 2dd3d68

Browse files
authored
fix: Exclude any checks from output if one passed (#466)
1 parent 93a0273 commit 2dd3d68

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

lib/core/utils/aggregateChecks.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@ axe.utils.aggregateChecks = function (nodeResOriginal) {
3333
});
3434

3535
// Find the result with the highest priority
36-
let priorities = anyAllNone(nodeResult, (c) => c.priority);
37-
nodeResult.priority = Math.max(
38-
priorities.all.reduce((a, b) => Math.max(a,b), 0),
39-
priorities.none.reduce((a, b) => Math.max(a,b), 0),
36+
const priorities = {
37+
all: nodeResult.all.reduce((a, b) => Math.max(a, b.priority), 0),
38+
none: nodeResult.none.reduce((a, b) => Math.max(a,b.priority), 0),
4039
// get the lowest passing of 'any' defaulting
4140
// to 0 by wrapping around 4 to 0 (inapplicable)
42-
priorities.any.reduce((a, b) => Math.min(a,b), 4) % 4
43-
);
41+
any: nodeResult.any.reduce((a, b) => Math.min(a, b.priority), 4) % 4
42+
};
43+
44+
nodeResult.priority = Math.max(priorities.all, priorities.none, priorities.any);
4445

4546
// Of each type, filter out all results not matching the final priority
4647
let impacts = [];
4748
checkTypes.forEach((type) => {
4849
nodeResult[type] = nodeResult[type].filter((check) => {
49-
return check.priority === nodeResult.priority;
50+
return (check.priority === nodeResult.priority &&
51+
check.priority === priorities[type]);
5052
});
5153
nodeResult[type].forEach((check) => impacts.push(check.impact));
5254
});

test/core/utils/aggregateChecks.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ describe('axe.utils.aggregateChecks', function() {
156156
}));
157157
assert.equal(checkResult.result, FAIL);
158158
});
159+
160+
it('ignores fail checks on any, if at least one passed', function () {
161+
var checkResult = axe.utils.aggregateChecks( createTestCheckResults({
162+
any: [false, undefined, true], // cantTell
163+
none: [true, false] // fail
164+
}));
165+
166+
assert.lengthOf(checkResult.any, 0);
167+
assert.lengthOf(checkResult.none, 1);
168+
});
169+
170+
it('includes cantTell checks from any if there are no fails', function () {
171+
var checkResult = axe.utils.aggregateChecks( createTestCheckResults({
172+
any: [undefined, undefined, false], // cantTell
173+
none: [undefined, false] // cantTell
174+
}));
175+
176+
assert.lengthOf(checkResult.any, 2);
177+
assert.lengthOf(checkResult.none, 1);
178+
});
159179
});
160180

161181
});

0 commit comments

Comments
 (0)