Comparing version 4.0.0 to 4.1.0
@@ -0,1 +1,5 @@ | ||
# 4.1.0 | ||
- You can now [filter violations by user impact](https://github.com/nickcolley/jest-axe#setting-the-level-of-user-impact) - thanks [@martiL](https://github.com/martiL). | ||
# 4.0.0 | ||
@@ -2,0 +6,0 @@ |
25
index.js
@@ -96,2 +96,16 @@ 'use strict' | ||
/** | ||
* Filters all violations by user impact | ||
* @param {object} violations result of the accessibilty check by axe | ||
* @param {array} impactLevels defines which impact level should be considered (e.g ['critical']) | ||
* The level of impact can be "minor", "moderate", "serious", or "critical". | ||
* @returns {object} violations filtered by impact level | ||
*/ | ||
function filterViolations (violations, impactLevels) { | ||
if (impactLevels && impactLevels.length > 0) { | ||
return violations.filter(v => impactLevels.includes(v.impact)) | ||
} | ||
return violations | ||
} | ||
/** | ||
* Custom Jest expect matcher, that can check aXe results for violations. | ||
@@ -104,8 +118,11 @@ * @param {object} object requires an instance of aXe's results object | ||
toHaveNoViolations (results) { | ||
const violations = results.violations | ||
if (typeof violations === 'undefined') { | ||
throw new Error('No violations found in aXe results object') | ||
if (typeof results.violations === "undefined") { | ||
throw new Error("No violations found in aXe results object"); | ||
} | ||
const violations = filterViolations( | ||
results.violations, | ||
results.toolOptions ? results.toolOptions.impactLevels : [] | ||
) | ||
const reporter = violations => { | ||
@@ -112,0 +129,0 @@ if (violations.length === 0) { |
{ | ||
"name": "jest-axe", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Custom Jest matcher for aXe for testing accessibility", | ||
@@ -33,3 +33,3 @@ "repository": "nickcolley/jest-axe", | ||
"devDependencies": { | ||
"@testing-library/react": "^10.2.1", | ||
"@testing-library/react": "^11.1.0", | ||
"@testing-library/vue": "^5.0.4", | ||
@@ -36,0 +36,0 @@ "@vue/server-test-utils": "^1.0.0-beta.31", |
@@ -235,2 +235,18 @@ # jest-axe | ||
### Setting the level of user impact. | ||
An array which defines which [impact](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md) level should be considered. This ensures that only violations with a specific impact on the user are considered. The level of impact can be "minor", "moderate", "serious", or "critical". | ||
```javascript | ||
// Global helper file (axe-helper.js) | ||
const { configureAxe } = require('jest-axe') | ||
const axe = configureAxe({ | ||
impactLevels: ['critical'], | ||
// ... | ||
}) | ||
module.exports = axe | ||
``` | ||
Refer to [Developing Axe-core Rules](https://github.com/dequelabs/axe-core/blob/master/doc/rule-development.md) for instructions on how to develop custom rules and checks. | ||
@@ -237,0 +253,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20803
162
261