Skip to content

Instantly share code, notes, and snippets.

@craigcarlyle
Created August 3, 2018 18:44
Show Gist options
  • Save craigcarlyle/a512ad8f592d9778304e417d348fe19d to your computer and use it in GitHub Desktop.
Save craigcarlyle/a512ad8f592d9778304e417d348fe19d to your computer and use it in GitHub Desktop.
a11y Cypress Commands
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