Created
August 3, 2018 18:44
-
-
Save craigcarlyle/a512ad8f592d9778304e417d348fe19d to your computer and use it in GitHub Desktop.
a11y Cypress Commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function a11yLinter(tagName: string) { | |
return cy.window().then((win: any) => { | |
return new Cypress.Promise(function(resolve: any, reject: any) { | |
win.axe.run(tagName, (err: any, results: any) => { | |
if (err) { | |
reject(err); | |
} | |
resolve(results.violations); | |
}); | |
}); | |
}); | |
} | |
function lintComponent(tagName: string) { | |
return a11yLinter(tagName).then((violations: any) => { | |
if (violations.length > 0) { | |
console.table(violations); | |
assert.equal(violations.length, 0, `${violations.length} a11y violation(s).`); | |
} | |
}); | |
} | |
Cypress.Commands.add("lintComponent", (tagName: string) => { | |
lintComponent(tagName); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment