Provide toBeAccessible matcher for Jasmine tests
Again, sorry about not being able to submit a proper pull request right now, but here's the code snippet I'm using to make accessibility testing stupid-easy in a Jasmine environment:
goog.provide('axs.testing.matchers');
/**
* A custom matcher that checks whether the element and all descendants pass
* a suite of accessibility checks.
*
* Example:
*
* expect(element).toBeAccessible();
*
*
* @this {*}
* @return {boolean}
*/
axs.testing.matchers.toBeAccessible = function() {
var auditConfig = new axs.AuditConfiguration();
auditConfig.scope = this.actual;
var results = axs.Audit.run(auditConfig);
var auditResults = axs.Audit.auditResults(results);
if (!this.isNot) {
this.message = auditResults.toString.bind(auditResults);
}
return auditResults.numErrors() == 0;
};
// Register the matchers globally if we're in a Jasmine environment
if (jasmine && beforeEach) {
beforeEach(function() {
this.addMatchers({
toBeAccessible: axs.testing.matchers.toBeAccessible
});
});
}
Working on it.
@ewinslow we'd like to keep this in a separate project because it is not a part of the core behavior of the library to support testing frameworks explicitly. In my opinion it's easier to maintain distinct components as separate projects so that if the Jasmine configuration API were to change, for example, we wouldn't need to issue a new release of the entire library to be up to date.
@ewinslow @alice the repo for the jasmine matcher is here. In progress: https://github.com/ckundo/jasmine_accessible
Similarly, I'm not sure where this should ideally live.