Skip to content

Commit

Permalink
chore: add target assert to queryFixture (#3564)
Browse files Browse the repository at this point in the history
* Adds an assert to the axe.testUtils.queryFixture() to guide developers in usage of the fixture helper
* Refactor to help VS Code pick up correct signatures
* Add JSDoc
* Whitespace fixes
  • Loading branch information
dbowling authored Jul 29, 2022
1 parent 6456029 commit 7843ff9
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 104 deletions.
56 changes: 28 additions & 28 deletions test/checks/navigation/heading-order.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
describe('heading-order', function() {
describe('heading-order', function () {
'use strict';

var checkContext = axe.testUtils.MockCheckContext();
var queryFixture = axe.testUtils.queryFixture;

afterEach(function() {
afterEach(function () {
checkContext.reset();
});

it('should store the heading order path and level for [role=heading] elements and return true', function() {
it('should store the heading order path and level for [role=heading] elements and return true', function () {
var vNode = queryFixture(
'<div role="heading" aria-level="1" id="target">One</div><div role="heading" aria-level="3">Three</div>'
);
Expand All @@ -31,7 +31,7 @@ describe('heading-order', function() {
});
});

it('should handle incorrect aria-level values', function() {
it('should handle incorrect aria-level values', function () {
var vNode = queryFixture(
'<div role="heading" aria-level="-1" id="target">One</div><div role="heading">Two</div>'
);
Expand All @@ -54,7 +54,7 @@ describe('heading-order', function() {
});
});

it('should allow high aria-level values', function() {
it('should allow high aria-level values', function () {
var vNode = queryFixture(
'<div role="heading" aria-level="12" id="target">One</div>'
);
Expand All @@ -73,7 +73,7 @@ describe('heading-order', function() {
});
});

it('should store the correct header level for hn tags and return true', function() {
it('should store the correct header level for hn tags and return true', function () {
var vNode = queryFixture('<h1 id="target">One</h1><h3>Three</h3>');
assert.isTrue(
axe.testUtils
Expand All @@ -94,7 +94,7 @@ describe('heading-order', function() {
});
});

it('should allow aria-level to override semantic level for hn tags and return true', function() {
it('should allow aria-level to override semantic level for hn tags and return true', function () {
var vNode = queryFixture(
'<h1 aria-level="2" id="target">Two</h1><h3 aria-level="4">Four</h3>'
);
Expand All @@ -117,8 +117,8 @@ describe('heading-order', function() {
});
});

it('should ignore aria-level on iframe when not used with role=heading', function() {
var vNode = queryFixture('<iframe aria-level="2"></iframe>');
it('should ignore aria-level on iframe when not used with role=heading', function () {
var vNode = queryFixture('<iframe aria-level="2" id="target"></iframe>');
axe.testUtils
.getCheckEvaluate('heading-order')
.call(checkContext, null, {}, vNode, { initiator: true });
Expand All @@ -132,7 +132,7 @@ describe('heading-order', function() {
});
});

it('should correctly give level on hn tag with role=heading', function() {
it('should correctly give level on hn tag with role=heading', function () {
var vNode = queryFixture(
'<h1 role="heading" id="target">One</h1><h3 role="heading">Three</h3>'
);
Expand All @@ -155,7 +155,7 @@ describe('heading-order', function() {
});
});

it('should return the heading level when an hn tag has an invalid aria-level', function() {
it('should return the heading level when an hn tag has an invalid aria-level', function () {
var vNode = queryFixture('<h1 aria-level="-1" id="target">One</h1>');
assert.isTrue(
axe.testUtils
Expand All @@ -172,7 +172,7 @@ describe('heading-order', function() {
});
});

it('should store the location of iframes', function() {
it('should store the location of iframes', function () {
var vNode = queryFixture(
'<h1 id="target">One</h1><iframe></iframe><h3>Three</h3>'
);
Expand All @@ -197,8 +197,8 @@ describe('heading-order', function() {
});
});

describe('after', function() {
it('should return false when header level increases by 2', function() {
describe('after', function () {
it('should return false when header level increases by 2', function () {
var results = [
{
data: {
Expand All @@ -224,7 +224,7 @@ describe('heading-order', function() {
assert.isFalse(checks['heading-order'].after(results)[1].result);
});

it('should return true when header level decreases by 1', function() {
it('should return true when header level decreases by 1', function () {
var results = [
{
data: {
Expand All @@ -250,7 +250,7 @@ describe('heading-order', function() {
assert.isTrue(checks['heading-order'].after(results)[1].result);
});

it('should return true when header level decreases by 2', function() {
it('should return true when header level decreases by 2', function () {
var results = [
{
data: {
Expand All @@ -276,7 +276,7 @@ describe('heading-order', function() {
assert.isTrue(checks['heading-order'].after(results)[1].result);
});

it('should return true when there is only one header', function() {
it('should return true when there is only one header', function () {
var results = [
{
data: {
Expand All @@ -294,7 +294,7 @@ describe('heading-order', function() {
assert.isTrue(checks['heading-order'].after(results)[0].result);
});

it('should return true when header level increases by 1', function() {
it('should return true when header level increases by 1', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -324,7 +324,7 @@ describe('heading-order', function() {
assert.isTrue(checks['heading-order'].after(results)[1].result);
});

it('should return true if heading levels are correct across iframes', function() {
it('should return true if heading levels are correct across iframes', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -374,7 +374,7 @@ describe('heading-order', function() {
assert.isTrue(afterResults[2].result);
});

it('should return false if heading levels are incorrect across iframes', function() {
it('should return false if heading levels are incorrect across iframes', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -424,7 +424,7 @@ describe('heading-order', function() {
assert.isTrue(afterResults[2].result);
});

it('should handle nested iframes', function() {
it('should handle nested iframes', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -493,7 +493,7 @@ describe('heading-order', function() {
assert.isTrue(afterResults[3].result);
});

it('sets the result to undefined when the heading is not in the map', function() {
it('sets the result to undefined when the heading is not in the map', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -522,7 +522,7 @@ describe('heading-order', function() {
assert.isUndefined(afterResults[1].result);
});

it('ignores frames for which there are no results', function() {
it('ignores frames for which there are no results', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -574,7 +574,7 @@ describe('heading-order', function() {
assert.isFalse(afterResults[2].result);
});

it('should not error if iframe is first result', function() {
it('should not error if iframe is first result', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -624,7 +624,7 @@ describe('heading-order', function() {
assert.isTrue(afterResults[2].result);
});

it('runs when the top frame has no heading', function() {
it('runs when the top frame has no heading', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -657,7 +657,7 @@ describe('heading-order', function() {
assert.isFalse(afterResults[1].result);
});

it('understand shadow DOM in ancestries', function() {
it('understand shadow DOM in ancestries', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -720,7 +720,7 @@ describe('heading-order', function() {
assert.isTrue(afterResults[3].result);
});

it('run when an in-between frame has no heading', function() {
it('run when an in-between frame has no heading', function () {
var results = [
{
data: {
Expand Down Expand Up @@ -779,7 +779,7 @@ describe('heading-order', function() {
assert.isTrue(afterResults[3].result);
});

it('can fail the second heading, if the first is excluded', function() {
it('can fail the second heading, if the first is excluded', function () {
var results = [
{
data: {
Expand Down
Loading

0 comments on commit 7843ff9

Please sign in to comment.