diff --git a/doc/check-options.md b/doc/check-options.md
index 0f5ffb41ab..889e012e42 100644
--- a/doc/check-options.md
+++ b/doc/check-options.md
@@ -35,6 +35,7 @@
- [target-size](#target-size)
- [region](#region)
- [inline-style-property](#inline-style-property)
+ - [invalid-children](#invalid-children)
## How Checks Work
@@ -526,3 +527,13 @@ This evaluate method is used in the following checks. Default vary between check
| `normalValue` | The value to use when `normal` is set, defaults to `0` |
If `minValue` and `maxValue` are both undefined, the check returns `false` if the property is used with !important. If done along with `noImportant: true`, the check returns false if the property is set at all in the style attribute.
+
+### invalid-children
+
+This evaluation method is used in the `list` and `definition-list` rule to determine whether its child nodes are allowed.
+
+| Option | Description |
+| ---------------- | :---------------------------------------------------------------------------------- |
+| `validNodeNames` | Nodes without role allowed as children |
+| `validRoles` | Roles allowed on child elements |
+| `divGroups` | Whether the child nodes can be grouped in a div without any role (false by default) |
diff --git a/lib/checks/lists/invalid-children-evaluate.js b/lib/checks/lists/invalid-children-evaluate.js
new file mode 100644
index 0000000000..fd9485fd32
--- /dev/null
+++ b/lib/checks/lists/invalid-children-evaluate.js
@@ -0,0 +1,75 @@
+import { isVisibleToScreenReaders } from '../../commons/dom';
+import { getExplicitRole } from '../../commons/aria';
+
+export default function invalidChildrenEvaluate(
+ node,
+ options = {},
+ virtualNode
+) {
+ const relatedNodes = [];
+ const issues = [];
+ if (!virtualNode.children) {
+ return undefined;
+ }
+
+ const vChildren = mapWithNested(virtualNode.children);
+ while (vChildren.length) {
+ const { vChild, nested } = vChildren.shift();
+ if (options.divGroups && !nested && isDivGroup(vChild)) {
+ if (!vChild.children) {
+ return undefined;
+ }
+ const vGrandChildren = mapWithNested(vChild.children, true);
+ vChildren.push(...vGrandChildren);
+ continue;
+ }
+
+ const issue = isInvalidChild(vChild, nested, options);
+ if (!issue) {
+ continue;
+ }
+ if (!issues.includes(issue)) {
+ issues.push(issue);
+ }
+ if (vChild?.actualNode?.nodeType === 1) {
+ relatedNodes.push(vChild.actualNode);
+ }
+ }
+ if (issues.length === 0) {
+ return false;
+ }
+
+ this.data({ values: issues.join(', ') });
+ this.relatedNodes(relatedNodes);
+ return true;
+}
+
+function isInvalidChild(
+ vChild,
+ nested,
+ { validRoles = [], validNodeNames = [] }
+) {
+ const { nodeName, nodeType, nodeValue } = vChild.props;
+ const selector = nested ? 'div > ' : '';
+ if (nodeType === 3 && nodeValue.trim() !== '') {
+ return selector + `#text`;
+ }
+ if (nodeType !== 1 || !isVisibleToScreenReaders(vChild)) {
+ return false;
+ }
+
+ const role = getExplicitRole(vChild);
+ if (role) {
+ return validRoles.includes(role) ? false : selector + `[role=${role}]`;
+ } else {
+ return validNodeNames.includes(nodeName) ? false : selector + nodeName;
+ }
+}
+
+function isDivGroup(vNode) {
+ return vNode.props.nodeName === 'div' && getExplicitRole(vNode) === null;
+}
+
+function mapWithNested(vNodes, nested = false) {
+ return vNodes.map(vChild => ({ vChild, nested }));
+}
diff --git a/lib/checks/lists/only-dlitems-evaluate.js b/lib/checks/lists/only-dlitems-evaluate.js
index f4ab72b49f..266d42a560 100644
--- a/lib/checks/lists/only-dlitems-evaluate.js
+++ b/lib/checks/lists/only-dlitems-evaluate.js
@@ -1,6 +1,9 @@
import { isVisibleToScreenReaders } from '../../commons/dom';
import { getRole, getExplicitRole } from '../../commons/aria';
+/**
+ * @deprecated
+ */
function onlyDlitemsEvaluate(node, options, virtualNode) {
const ALLOWED_ROLES = ['definition', 'term', 'list'];
const base = {
diff --git a/lib/checks/lists/only-dlitems.json b/lib/checks/lists/only-dlitems.json
index 580af8b16f..91ddf26b16 100644
--- a/lib/checks/lists/only-dlitems.json
+++ b/lib/checks/lists/only-dlitems.json
@@ -1,11 +1,16 @@
{
"id": "only-dlitems",
- "evaluate": "only-dlitems-evaluate",
+ "evaluate": "invalid-children-evaluate",
+ "options": {
+ "validRoles": ["definition", "term", "listitem"],
+ "validNodeNames": ["dt", "dd"],
+ "divGroups": true
+ },
"metadata": {
"impact": "serious",
"messages": {
- "pass": "List element only has direct children that are allowed inside
or
elements",
- "fail": "List element has direct children that are not allowed inside
or
elements"
+ "pass": "dl element only has direct children that are allowed inside;
,
, or
elements",
+ "fail": "dl element has direct children that are not allowed: ${data.values}"
}
}
}
diff --git a/lib/checks/lists/only-listitems-evaluate.js b/lib/checks/lists/only-listitems-evaluate.js
index dbcf22c25e..93ab74adfa 100644
--- a/lib/checks/lists/only-listitems-evaluate.js
+++ b/lib/checks/lists/only-listitems-evaluate.js
@@ -1,6 +1,9 @@
import { isVisibleToScreenReaders } from '../../commons/dom';
import { getRole } from '../../commons/aria';
+/**
+ * @deprecated
+ */
function onlyListitemsEvaluate(node, options, virtualNode) {
let hasNonEmptyTextNode = false;
let atLeastOneListitem = false;
diff --git a/lib/checks/lists/only-listitems.json b/lib/checks/lists/only-listitems.json
index 26426048be..946eeadca4 100644
--- a/lib/checks/lists/only-listitems.json
+++ b/lib/checks/lists/only-listitems.json
@@ -1,14 +1,15 @@
{
"id": "only-listitems",
- "evaluate": "only-listitems-evaluate",
+ "evaluate": "invalid-children-evaluate",
+ "options": {
+ "validRoles": ["listitem"],
+ "validNodeNames": ["li"]
+ },
"metadata": {
"impact": "serious",
"messages": {
"pass": "List element only has direct children that are allowed inside
elements",
- "fail": {
- "default": "List element has direct children that are not allowed inside
elements",
- "roleNotValid": "List element has direct children with a role that is not allowed: ${data.roles}"
- }
+ "fail": "List element has direct children that are not allowed: ${data.values}"
}
}
}
diff --git a/lib/rules/no-role-matches.js b/lib/rules/no-role-matches.js
index 968452ec00..d9ee28f99b 100644
--- a/lib/rules/no-role-matches.js
+++ b/lib/rules/no-role-matches.js
@@ -1,5 +1,5 @@
-function noRoleMatches(node) {
- return !node.getAttribute('role');
+function noRoleMatches(node, vNode) {
+ return !vNode.attr('role');
}
export default noRoleMatches;
diff --git a/locales/_template.json b/locales/_template.json
index 1d3201fbf0..4bf9ce275f 100644
--- a/locales/_template.json
+++ b/locales/_template.json
@@ -782,15 +782,12 @@
}
},
"only-dlitems": {
- "pass": "List element only has direct children that are allowed inside
or
elements",
- "fail": "List element has direct children that are not allowed inside
or
elements"
+ "pass": "dl element only has direct children that are allowed inside;
,
, or
elements",
+ "fail": "dl element has direct children that are not allowed: ${data.values}"
},
"only-listitems": {
"pass": "List element only has direct children that are allowed inside
elements",
- "fail": {
- "default": "List element has direct children that are not allowed inside
elements",
- "roleNotValid": "List element has direct children with a role that is not allowed: ${data.roles}"
- }
+ "fail": "List element has direct children that are not allowed: ${data.values}"
},
"structured-dlitems": {
"pass": "When not empty, element has both
and
elements",
diff --git a/test/checks/lists/only-dlitems.js b/test/checks/lists/only-dlitems.js
index 29d7040bf6..fd7af0dc06 100644
--- a/test/checks/lists/only-dlitems.js
+++ b/test/checks/lists/only-dlitems.js
@@ -1,349 +1,227 @@
-describe('only-dlitems', function () {
- 'use strict';
+describe('only-dlitems', () => {
+ const fixture = document.getElementById('fixture');
+ const checkSetup = axe.testUtils.checkSetup;
+ const checkContext = axe.testUtils.MockCheckContext();
+ const checkEvaluate = axe.testUtils.getCheckEvaluate('only-dlitems');
- var fixture = document.getElementById('fixture');
- var checkSetup = axe.testUtils.checkSetup;
- var shadowSupport = axe.testUtils.shadowSupport;
- var checkContext = axe.testUtils.MockCheckContext();
-
- afterEach(function () {
- fixture.innerHTML = '';
+ afterEach(() => {
checkContext.reset();
});
- it('should return false if the list has no contents', function () {
- var checkArgs = checkSetup('
');
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if the list has no contents', () => {
+ const checkArgs = checkSetup('
');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return true if the list has non-dd/dt contents', function () {
- var checkArgs = checkSetup('
Not a list
');
+ it('should return true if the list has non-dd/dt contents', () => {
+ const checkArgs = checkSetup('
Not a list
');
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
assert.deepEqual(checkContext._relatedNodes, [fixture.querySelector('p')]);
+ assert.deepEqual(checkContext._data, { values: 'p' });
});
- it('should return true if the list has non-dd content through role change', function () {
- var checkArgs = checkSetup(
+ it('should return true if the list has non-dd content through role change', () => {
+ const checkArgs = checkSetup(
'
Not a list
'
);
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: '[role=menuitem]' });
});
- it('should return true if the list has non-dt content through role change', function () {
- var checkArgs = checkSetup(
+ it('should return true if the list has non-dt content through role change', () => {
+ const checkArgs = checkSetup(
'
Not a list
'
);
-
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: '[role=menuitem]' });
});
- it('should return false if the list has only a dd', function () {
- var checkArgs = checkSetup('
A list
');
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if the list has only a dd', () => {
+ const checkArgs = checkSetup('
A list
');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return true if is used along side dt with its role changed', function () {
- var checkArgs = checkSetup(
+ it('should return true if is used along side dt with its role changed', () => {
+ const checkArgs = checkSetup(
'
A list
'
);
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: '[role=menuitem]' });
});
- it('should return false if the list has only a dt', function () {
- var checkArgs = checkSetup('
A list
');
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if the list has only a dt', () => {
+ const checkArgs = checkSetup('
A list
');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has dt and dd with child content', function () {
- var checkArgs = checkSetup(
+ it('should return false if the list has dt and dd with child content', () => {
+ const checkArgs = checkSetup(
'
An item
A list
'
);
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has dt and dd', function () {
- var checkArgs = checkSetup(
+ it('should return false if the list has dt and dd', () => {
+ const checkArgs = checkSetup(
'
An item
A list
'
);
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has dt, dd and a comment', function () {
- var checkArgs = checkSetup(
+ it('should return false if the list has dt, dd and a comment', () => {
+ const checkArgs = checkSetup(
'
An item
A list
'
);
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return true if the list has a dt and dd with other content', function () {
- var checkArgs = checkSetup(
+ it('should return true if the list has a dt and dd with other content', () => {
+ const checkArgs = checkSetup(
'
Item one
Description
Not a list
'
);
-
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
assert.deepEqual(checkContext._relatedNodes, [fixture.querySelector('p')]);
+ assert.deepEqual(checkContext._data, { values: 'p' });
});
- it('should return true if the list has a textNode as a child', function () {
- var checkArgs = checkSetup(
+ it('should return true if the list has a textNode as a child', () => {
+ const checkArgs = checkSetup(
'
hi
hello
hi
'
);
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
assert.deepEqual(checkContext._relatedNodes, []);
+ assert.deepEqual(checkContext._data, { values: '#text' });
});
- it('should return false if is used along side dt', function () {
- var checkArgs = checkSetup(
+ it('should return false if is used along side dt', () => {
+ const checkArgs = checkSetup(
'
A list
'
);
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if is used along side dt', function () {
- var checkArgs = checkSetup(
+ it('should return false if is used along side dt', () => {
+ const checkArgs = checkSetup(
'
'
);
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if is used along side dt', function () {
- var checkArgs = checkSetup(
+ it('should return false if is used along side dt', () => {
+ const checkArgs = checkSetup(
'
A list
'
);
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has dt and dd inside a div group', function () {
- var checkArgs = checkSetup(
+ it('should return false if the list has dt and dd inside a div group', () => {
+ const checkArgs = checkSetup(
'
An item
A list
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return true if the list has dt and dd inside a div group with a role', function () {
- var checkArgs = checkSetup(
- '
An item
A list
'
- );
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
+ it('should return true if the list has dt and dd inside a div group with a role', () => {
+ const checkArgs = checkSetup(
+ '
An item
A list
'
);
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: '[role=list]' });
});
- it('should return true if the list mixed items inside a div group with a role', function () {
- var checkArgs = checkSetup(
+ it('should return true if the list mixed items inside a div group with a role', () => {
+ const checkArgs = checkSetup(
'
An item
A list
Not a list
'
);
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: 'div > p' });
});
- it('should return false if there is an empty div', function () {
- var checkArgs = checkSetup('
');
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if there is an empty div', () => {
+ const checkArgs = checkSetup('
');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('returns false if there are display:none elements that normally would not be allowed', function () {
- var checkArgs = checkSetup(
+ it('returns false if there are display:none elements that normally would not be allowed', () => {
+ const checkArgs = checkSetup(
'
An item
A list
heading
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return true if there is a div with text', function () {
- var checkArgs = checkSetup('
text
');
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return true if there is a div with text', () => {
+ const checkArgs = checkSetup('
text
');
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: 'div > #text' });
});
- it('returns false if there are visibility:hidden elements that normally would not be allowed', function () {
- var checkArgs = checkSetup(
+ it('returns false if there are visibility:hidden elements that normally would not be allowed', () => {
+ const checkArgs = checkSetup(
'
An item
A list
heading
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return true if there is a div with non-dd / dt elements', function () {
- var checkArgs = checkSetup('
text
');
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
+ it('should return true if there is a div with non-dd / dt elements', () => {
+ const checkArgs = checkSetup(
+ '
text
'
);
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: 'div > p' });
});
- it('returns false if there are aria-hidden=true elements that normally would not be allowed', function () {
- var checkArgs = checkSetup(
+ it('returns false if there are aria-hidden=true elements that normally would not be allowed', () => {
+ const checkArgs = checkSetup(
'
An item
A list
heading
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('returns true if there are aria-hidden=false elements that normally would not be allowed', function () {
- var checkArgs = checkSetup(
+ it('returns true if there are aria-hidden=false elements that normally would not be allowed', () => {
+ const checkArgs = checkSetup(
'
An item
A list
heading
'
);
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: 'h1' });
});
- (shadowSupport.v1 ? it : xit)(
- 'should return false in a shadow DOM pass',
- function () {
- var node = document.createElement('div');
+ describe('shadow DOM', () => {
+ it('should return false in a shadow DOM pass', () => {
+ const node = document.createElement('div');
node.innerHTML = '
';
- var checkArgs = checkSetup(node, 'dl');
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-dlitems')
- .apply(checkContext, checkArgs)
- );
- }
- );
+ const checkArgs = checkSetup(node, 'dl');
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, { values: 'p' });
+ });
+ });
});
diff --git a/test/checks/lists/only-listitems.js b/test/checks/lists/only-listitems.js
index 4e32294cb0..e4134b035e 100644
--- a/test/checks/lists/only-listitems.js
+++ b/test/checks/lists/only-listitems.js
@@ -1,160 +1,114 @@
-describe('only-listitems', function () {
- 'use strict';
+describe('only-listitems', () => {
+ const fixture = document.getElementById('fixture');
+ const checkSetup = axe.testUtils.checkSetup;
+ const checkContext = axe.testUtils.MockCheckContext();
+ const checkEvaluate = axe.testUtils.getCheckEvaluate('only-listitems');
- var fixture = document.getElementById('fixture');
- var checkSetup = axe.testUtils.checkSetup;
- var shadowSupport = axe.testUtils.shadowSupport;
- var checkContext = axe.testUtils.MockCheckContext();
-
- afterEach(function () {
- fixture.innerHTML = '';
+ afterEach(() => {
checkContext.reset();
});
- it('should return false if the list has no contents', function () {
- var checkArgs = checkSetup('');
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if the list has no contents', () => {
+ const checkArgs = checkSetup('');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has only spaces as content', function () {
- var checkArgs = checkSetup('');
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if the list has only spaces as content', () => {
+ const checkArgs = checkSetup('');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has whitespace', function () {
- var checkArgs = checkSetup('
Item
');
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if the list has whitespace', () => {
+ const checkArgs = checkSetup('
Item
');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has only an element with role listitem', function () {
- var checkArgs = checkSetup(
+ it('should return false if the list has only an element with role listitem', () => {
+ const checkArgs = checkSetup(
'
A list
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has only multiple mixed elements with role listitem', function () {
- var checkArgs = checkSetup(
+ it('should return false if the list has only multiple mixed elements with role listitem', () => {
+ const checkArgs = checkSetup(
'
list
list
list
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has non-li comments', function () {
- var checkArgs = checkSetup(
+ it('should return false if the list has non-li comments', () => {
+ const checkArgs = checkSetup(
'
Item
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return true if the list has non-li text contents', function () {
- var checkArgs = checkSetup('
Item
Not an item');
-
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
+ it('should return true if the list has non-li text contents', () => {
+ const checkArgs = checkSetup(
+ '
Item
Not an item'
);
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._data, {
+ values: '#text'
+ });
});
- it('should return true if the list has non-li contents', function () {
- var checkArgs = checkSetup('
Not a list
');
-
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return true if the list has non-li contents', () => {
+ const checkArgs = checkSetup('
Not a list
');
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
assert.deepEqual(checkContext._relatedNodes, [fixture.querySelector('p')]);
+ assert.deepEqual(checkContext._data, {
+ values: 'p'
+ });
});
- it('should return false if the list has only an li with child content', function () {
- var checkArgs = checkSetup('
A list
');
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if the list has only an li with child content', () => {
+ const checkArgs = checkSetup('
A list
');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if the list has only an li', function () {
- var checkArgs = checkSetup('
A list
');
-
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ it('should return false if the list has only an li', () => {
+ const checkArgs = checkSetup('
A list
');
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return true if the list has an li with other content', function () {
- var checkArgs = checkSetup(
+ it('should return true if the list has an li with other content', () => {
+ const checkArgs = checkSetup(
'
A list
Not a list
'
);
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
assert.deepEqual(checkContext._relatedNodes, [fixture.querySelector('p')]);
+ assert.deepEqual(checkContext._data, {
+ values: 'p'
+ });
});
- it('should return false if the list has at least one li while others have their roles changed', function () {
- var checkArgs = checkSetup(
+ it('should return true if the list has at least one li while others have their roles changed', () => {
+ const checkArgs = checkSetup(
'
A list item
Not a list item
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ assert.deepEqual(checkContext._relatedNodes, [
+ fixture.querySelector('[role="menuitem"]')
+ ]);
+ assert.deepEqual(checkContext._data, {
+ values: '[role=menuitem]'
+ });
});
- it('should return true if the list has only li items with their roles changed', function () {
- var checkArgs = checkSetup(
+ it('should return true if the list has only li items with their roles changed', () => {
+ const checkArgs = checkSetup(
'
Not a list item
Not a list item
'
);
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
assert.deepEqual(checkContext._data, {
- messageKey: 'roleNotValid',
- roles: 'menuitem'
+ values: '[role=menuitem]'
});
assert.deepEqual(checkContext._relatedNodes, [
fixture.querySelector('#fail1'),
@@ -162,153 +116,133 @@ describe('only-listitems', function () {
]);
});
- it('should return true if is used along side only li items with their roles changed', function () {
- var checkArgs = checkSetup(
+ it('should return true if is used along side only li items with their roles changed', () => {
+ const checkArgs = checkSetup(
'
Not a list item
'
);
- assert.isTrue(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isTrue(checkEvaluate.apply(checkContext, checkArgs));
+ console.log(checkContext._data);
+ assert.deepEqual(checkContext._data, {
+ values: '[role=menuitem]'
+ });
});
- it('should return false if is used along side li', function () {
- var checkArgs = checkSetup(
+ it('should return false if is used along side li', () => {
+ const checkArgs = checkSetup(
'
A list
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if is used along side li', function () {
- var checkArgs = checkSetup(
+ it('should return false if is used along side li', () => {
+ const checkArgs = checkSetup(
'
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('should return false if is used along side li', function () {
- var checkArgs = checkSetup(
+ it('should return false if is used along side li', () => {
+ const checkArgs = checkSetup(
'
A list
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('returns false if there are display:none elements that normally would not be allowed', function () {
- var checkArgs = checkSetup(
+ it('returns false if there are display:none elements that normally would not be allowed', () => {
+ const checkArgs = checkSetup(
'
An item
heading
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('returns false if there are visibility:hidden elements that normally would not be allowed', function () {
- var checkArgs = checkSetup(
+ it('returns false if there are visibility:hidden elements that normally would not be allowed', () => {
+ const checkArgs = checkSetup(
'
An item
heading
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('returns false if there are aria-hidden=true elements that normally would not be allowed', function () {
- var checkArgs = checkSetup(
+ it('returns false if there are aria-hidden=true elements that normally would not be allowed', () => {
+ const checkArgs = checkSetup(
'
An item
heading
'
);
- assert.isFalse(
- axe.testUtils
- .getCheckEvaluate('only-listitems')
- .apply(checkContext, checkArgs)
- );
+ assert.isFalse(checkEvaluate.apply(checkContext, checkArgs));
});
- it('returns true if there are aria-hidden=false elements that normally would not be allowed', function () {
- var checkArgs = checkSetup(
+ it('returns true if there are aria-hidden=false elements that normally would not be allowed', () => {
+ const checkArgs = checkSetup(
'