Skip to content

Commit

Permalink
prefer const
Browse files Browse the repository at this point in the history
  • Loading branch information
gaiety-deque committed Jun 7, 2024
1 parent 743775d commit 403b502
Show file tree
Hide file tree
Showing 36 changed files with 470 additions and 462 deletions.
6 changes: 3 additions & 3 deletions test/rule-matches/aria-allowed-attr-matches.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('aria-allowed-attr-matches', function () {
'use strict';

let queryFixture = axe.testUtils.queryFixture;
const queryFixture = axe.testUtils.queryFixture;
let rule;

beforeEach(function () {
Expand All @@ -13,15 +13,15 @@ describe('aria-allowed-attr-matches', function () {
});

it('should return true on elements that have aria attributes', function () {
let vNode = queryFixture(
const vNode = queryFixture(
'<div role="button" id="target" aria-label="Thing 1" aria-mccheddarton="Unsupported thing 2"></div>'
);

assert.isTrue(rule.matches(null, vNode));
});

it('should return false on elements that have no aria attributes', function () {
let vNode = queryFixture('<div role="button" id="target"></div>');
const vNode = queryFixture('<div role="button" id="target"></div>');

assert.isFalse(rule.matches(null, vNode));
});
Expand Down
10 changes: 6 additions & 4 deletions test/rule-matches/aria-allowed-role-matches.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
describe('aria-allowed-role-matches', function () {
'use strict';

let queryFixture = axe.testUtils.queryFixture;
const queryFixture = axe.testUtils.queryFixture;
let rule;

beforeEach(function () {
rule = axe.utils.getRule('aria-allowed-role');
});

it('return false (no matches) for a <link> with a href to have any invalid role', function () {
let vNode = queryFixture(
const vNode = queryFixture(
'<link id="target" href="/example.com" role="invalid-role"></link>'
);
assert.isFalse(rule.matches(null, vNode));
});

it('return true for input with redundant role', function () {
let vNode = queryFixture('<input id="target" type="text" role="textbox"/>');
const vNode = queryFixture(
'<input id="target" type="text" role="textbox"/>'
);
assert.isTrue(rule.matches(null, vNode));
});

it('return true for element with valid role', function () {
let vNode = queryFixture('<ol id="target" role="listbox"/>');
const vNode = queryFixture('<ol id="target" role="listbox"/>');
assert.isTrue(rule.matches(null, vNode));
});
});
10 changes: 5 additions & 5 deletions test/rule-matches/aria-has-attr-matches.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe('aria-has-attr-matches', function () {
'use strict';

let queryFixture = axe.testUtils.queryFixture;
let fixtureSetup = axe.testUtils.fixtureSetup;
const queryFixture = axe.testUtils.queryFixture;
const fixtureSetup = axe.testUtils.fixtureSetup;
let rule;

beforeEach(function () {
Expand All @@ -14,16 +14,16 @@ describe('aria-has-attr-matches', function () {
});

it('should return false if an element has no attributes', function () {
let vNode = fixtureSetup('<div></div>');
const vNode = fixtureSetup('<div></div>');
assert.isFalse(rule.matches(null, vNode));
});

it('should return false if an element has no ARIA attributes', function () {
let vNode = queryFixture('<div id="target"></div>');
const vNode = queryFixture('<div id="target"></div>');
assert.isFalse(rule.matches(null, vNode));
});
it('should return true if an element has ARIA attributes', function () {
let vNode = queryFixture('<div id="target" aria-bats="monkeys"></div>');
const vNode = queryFixture('<div id="target" aria-bats="monkeys"></div>');
assert.isTrue(rule.matches(null, vNode));
});
});
18 changes: 9 additions & 9 deletions test/rule-matches/aria-hidden-focus-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('aria-hidden-focus-matches', function () {
'use strict';

let rule;
let queryFixture = axe.testUtils.queryFixture;
const queryFixture = axe.testUtils.queryFixture;

beforeEach(function () {
rule = axe.utils.getRule('aria-hidden-focus');
Expand All @@ -13,44 +13,44 @@ describe('aria-hidden-focus-matches', function () {
});

it('return true when there is no parent with aria-hidden', function () {
let vNode = queryFixture('<div id="target">' + '</div>');
let actual = rule.matches(vNode.actualNode);
const vNode = queryFixture('<div id="target">' + '</div>');
const actual = rule.matches(vNode.actualNode);
assert.isTrue(actual);
});

it('return false when has a parent element with aria-hidden', function () {
let vNode = queryFixture(
const vNode = queryFixture(
'<div aria-hidden="true">' +
'<div id="target" aria-hidden="true">' +
'</div>' +
'</div>'
);
let actual = rule.matches(vNode.actualNode);
const actual = rule.matches(vNode.actualNode);
assert.isFalse(actual);
});

it('return false when has any parent element with aria-hidden', function () {
let vNode = queryFixture(
const vNode = queryFixture(
'<div aria-hidden="true">' +
'<div>' +
'<div id="target" aria-hidden="true">' +
'</div>' +
'</div>' +
'</div>'
);
let actual = rule.matches(vNode.actualNode);
const actual = rule.matches(vNode.actualNode);
assert.isFalse(actual);
});

it('return false when has any parent element with aria-hidden', function () {
let vNode = queryFixture(
const vNode = queryFixture(
'<div aria-hidden="true">' +
'<div aria-hidden="true">' +
'<button id="target">btn</button>' +
'</div>' +
'</div>'
);
let actual = rule.matches(vNode.actualNode);
const actual = rule.matches(vNode.actualNode);
assert.isFalse(actual);
});
});
8 changes: 4 additions & 4 deletions test/rule-matches/aria-required-children-matches.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe('aria-required-children-matches', function () {
'use strict';

let fixture = document.getElementById('fixture');
let queryFixture = axe.testUtils.queryFixture;
const fixture = document.getElementById('fixture');
const queryFixture = axe.testUtils.queryFixture;
let rule;

beforeEach(function () {
Expand All @@ -14,12 +14,12 @@ describe('aria-required-children-matches', function () {
});

it('should return true for a role that requires children', function () {
let vNode = queryFixture('<div id="target" role="list"></div>');
const vNode = queryFixture('<div id="target" role="list"></div>');
assert.isTrue(rule.matches(null, vNode));
});

it('should return false for a role that does not require children', function () {
let vNode = queryFixture('<div id="target" role="alert"></div>');
const vNode = queryFixture('<div id="target" role="alert"></div>');
assert.isFalse(rule.matches(null, vNode));
});
});
8 changes: 4 additions & 4 deletions test/rule-matches/aria-required-parent-matches.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe('aria-required-parent-matches', function () {
'use strict';

let fixture = document.getElementById('fixture');
let queryFixture = axe.testUtils.queryFixture;
const fixture = document.getElementById('fixture');
const queryFixture = axe.testUtils.queryFixture;
let rule;

beforeEach(function () {
Expand All @@ -14,12 +14,12 @@ describe('aria-required-parent-matches', function () {
});

it('should return true for a role that requires parent', function () {
let vNode = queryFixture('<div id="target" role="listitem"></div>');
const vNode = queryFixture('<div id="target" role="listitem"></div>');
assert.isTrue(rule.matches(null, vNode));
});

it('should return false for a role that does not require parent', function () {
let vNode = queryFixture('<div id="target" role="alert"></div>');
const vNode = queryFixture('<div id="target" role="alert"></div>');
assert.isFalse(rule.matches(null, vNode));
});
});
40 changes: 20 additions & 20 deletions test/rule-matches/autocomplete-matches.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe('autocomplete-matches', function () {
'use strict';
let fixture = document.getElementById('fixture');
let queryFixture = axe.testUtils.queryFixture;
let rule = axe.utils.getRule('autocomplete-valid');
const fixture = document.getElementById('fixture');
const queryFixture = axe.testUtils.queryFixture;
const rule = axe.utils.getRule('autocomplete-valid');

afterEach(function () {
fixture.innerHTML = '';
Expand All @@ -13,54 +13,54 @@ describe('autocomplete-matches', function () {
});

it('returns true for input elements', function () {
let vNode = queryFixture('<input id="target" autocomplete="foo">');
const vNode = queryFixture('<input id="target" autocomplete="foo">');
assert.isTrue(rule.matches(null, vNode));
});

it('returns true for select elements', function () {
let vNode = queryFixture('<select id="target" autocomplete="foo">');
const vNode = queryFixture('<select id="target" autocomplete="foo">');
assert.isTrue(rule.matches(null, vNode));
});

it('returns true for textarea elements', function () {
let vNode = queryFixture('<textarea id="target" autocomplete="foo">');
const vNode = queryFixture('<textarea id="target" autocomplete="foo">');
assert.isTrue(rule.matches(null, vNode));
});

it('returns false for buttons elements', function () {
let vNode = queryFixture('<button id="target" autocomplete="foo">');
const vNode = queryFixture('<button id="target" autocomplete="foo">');
assert.isFalse(rule.matches(null, vNode));
});

it('should return false for non-form field elements', function () {
let vNode = queryFixture('<div id="target" autocomplete="foo">');
const vNode = queryFixture('<div id="target" autocomplete="foo">');
assert.isFalse(rule.matches(null, vNode));
});

it('returns false for input buttons', function () {
['reset', 'submit', 'button'].forEach(function (type) {
let vNode = queryFixture(
const vNode = queryFixture(
'<input id="target" type="' + type + '" autocomplete="foo">'
);
assert.isFalse(rule.matches(null, vNode));
});
});

it('returns false for elements with an empty autocomplete', function () {
let vNode = queryFixture('<input id="target" autocomplete=" ">');
const vNode = queryFixture('<input id="target" autocomplete=" ">');
assert.isFalse(rule.matches(null, vNode));
});

it('returns false for intput[type=hidden]', function () {
let vNode = queryFixture(
const vNode = queryFixture(
'<input id="target" type="hidden" autocomplete="foo">'
);
assert.isFalse(rule.matches(null, vNode));
});

it('returns false for disabled fields', function () {
['input', 'select', 'textarea'].forEach(function (tagName) {
let vNode = queryFixture(
const vNode = queryFixture(
'<' + tagName + ' id="target" disabled autocomplete="foo">'
);
assert.isFalse(rule.matches(null, vNode));
Expand All @@ -69,7 +69,7 @@ describe('autocomplete-matches', function () {

it('returns false for aria-disabled=true fields', function () {
['input', 'select', 'textarea'].forEach(function (tagName) {
let vNode = queryFixture(
const vNode = queryFixture(
'<' + tagName + ' id="target" aria-disabled="true" autocomplete="foo">'
);
assert.isFalse(rule.matches(null, vNode));
Expand All @@ -78,17 +78,17 @@ describe('autocomplete-matches', function () {

it('returns true for aria-disabled=false fields', function () {
['input', 'select', 'textarea'].forEach(function (tagName) {
let vNode = queryFixture(
const vNode = queryFixture(
'<' + tagName + ' id="target" aria-disabled="false" autocomplete="foo">'
);
assert.isTrue(rule.matches(null, vNode));
});
});

it('returns false for non-widget roles with tabindex=-1', function () {
let nonWidgetRoles = ['application', 'fakerole', 'main'];
const nonWidgetRoles = ['application', 'fakerole', 'main'];
nonWidgetRoles.forEach(function (role) {
let vNode = queryFixture(
const vNode = queryFixture(
'<input id="target" role="' +
role +
'" tabindex="-1" autocomplete="foo">'
Expand All @@ -101,9 +101,9 @@ describe('autocomplete-matches', function () {
});

it('returns true for form fields with a widget role with tabindex=-1', function () {
let nonWidgetRoles = ['button', 'menuitem', 'slider'];
const nonWidgetRoles = ['button', 'menuitem', 'slider'];
nonWidgetRoles.forEach(function (role) {
let vNode = queryFixture(
const vNode = queryFixture(
'<input id="target" role="' +
role +
'" tabindex="-1" autocomplete="foo">'
Expand All @@ -114,15 +114,15 @@ describe('autocomplete-matches', function () {

it('returns true for form fields with tabindex=-1', function () {
['input', 'select', 'textarea'].forEach(function (tagName) {
let vNode = queryFixture(
const vNode = queryFixture(
'<' + tagName + ' id="target" tabindex="-1" autocomplete="foo">'
);
assert.isTrue(rule.matches(null, vNode));
});
});

it('returns false for off screen and hidden form fields with tabindex=-1', function () {
let vNode = queryFixture(
const vNode = queryFixture(
'<div aria-hidden="true">' +
'<input id="target" tabindex="-1" style="position:absolute; top:-9999em" autocomplete="foo">' +
'</div>'
Expand Down
Loading

0 comments on commit 403b502

Please sign in to comment.