Skip to content

Commit

Permalink
Merge pull request #25 from aliciasedlock/logging-updates
Browse files Browse the repository at this point in the history
Add more descriptive violation logging
  • Loading branch information
nathanhammond committed Jun 11, 2016
2 parents ab7638b + 1054386 commit c2c1d7a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
30 changes: 26 additions & 4 deletions content-for/test-body-footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,35 @@
a11yCheckCallback: function(results) {
var violations = results.violations;

for (var i = 0, l = violations.length; i < l; i++) {
Ember.Logger.error('Violation #' + (i + 1), violations[i]);
}
if (violations.length) {
Ember.Logger.error('ACCESSIBILITY VIOLATIONS: ' + violations.length);

for (var i = 0, l = violations.length; i < l; i++) {
var violation = violations[i];
var violationNodes = axe.ember.generateNodesArray(violation.nodes);

Ember.assert('The page should have no accessibility violations.', !violations.length);
Ember.Logger.warn(violation.impact.toUpperCase() + ': ' + violation.help);
Ember.Logger.info('Offending markup (' + violation.nodes.length + ')');
Ember.Logger.debug(violationNodes);
Ember.Logger.info('Additional info: ' + violation.helpUrl);
Ember.Logger.info('-------------------------------------');
}
}
Ember.assert('The page should have no accessibility violations. Please check the developer console for more details.', !violations.length);
},

/**
* Takes the violations' nodes param and converts it to
* an array that constains only offending markup HTML.
* @param {Array} nodes
* @return {Array}
*/
generateNodesArray: function(nodes) {
return nodes.map(function(node) {
return node.html;
});
},

/**
* Used as a callback for afterRender. Simply runs axe.a11yCheck and passes
* the results to a11yCheckCallback.
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test-body-footer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ test('a11yCheckCallback should log any violations and throw an error', function(

assert.throws(() => {
axe.ember.a11yCheckCallback({ violations: [ {}, {} ] });
}, 'The page should have no accessibility violations.');
}, 'The page should have no accessibility violations. Please check the developer console for more details.');

assert.ok(loggerStub.calledTwice);
assert.equal(loggerStub.callCount, 1, 'An error is thrown when there are violations');
});

/* axe.ember.afterRender */
Expand Down

0 comments on commit c2c1d7a

Please sign in to comment.