Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
feat: Add disableRules method for disabling individual rules
Browse files Browse the repository at this point in the history
* feat: add method to the axe builder that enables providing a list of rules to be skipped during analysis

* test: add tests for disableRules method + document it in the README.md
  • Loading branch information
JayKid authored and WilcoFiers committed Nov 15, 2017
1 parent 059d18d commit 3833c59
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ AxeBuilder(driver)
.withTags(['wcag2a', 'wcag2aa']);
```

### AxeBuilder#disableRules(rules:Mixed)

Skips verification of the rules provided. Accepts a String of a single rule ID or an Array of multiple rule IDs. **Subsequent calls to `AxeBuilder#options`, `AxeBuilder#disableRules` will override specified options.**

```javascript
AxeBuilder(driver)
.disableRules('color-contrast');
```

or use it combined with some specified tags:

```javascript
AxeBuilder(driver)
.withTags(['wcag2a', 'wcag2aa'])
.disableRules('color-contrast');
```


### AxeBuilder#configure(config:Object)

Inject an aXe configuration object to modify the ruleset before running Analyze. Subsequent calls to this
Expand Down
20 changes: 20 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ AxeBuilder.prototype.withTags = function (tags) {

return this;
};

/**
* Set the list of rules to skip when running an analysis
* @param {Array|String} rules Array of rule IDs, or a single rule ID as a string
* @return {AxeBuilder}
*/
AxeBuilder.prototype.disableRules = function(rules) {
rules = Array.isArray(rules) ? rules : [rules];
this._options = this._options || {};
this._options.rules = {};

rules.forEach(function(rulesConfiguration, ruleToDisable) {
rulesConfiguration[ruleToDisable] = {
enabled: false
};
}.bind(null, this._options.rules));

return this;
};

/**
* Configure aXe before running analyze. *Does not chain.*
* @param {Object} config Configuration object to use in analysis
Expand Down
33 changes: 33 additions & 0 deletions test/unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,39 @@ describe('Builder', function () {
});
});

describe('disableRules', function () {
it('should properly populate _options.rules with the provided parameter', function () {
var builder = new Builder();
var colorRule = 'color-contrast';
var landmarkRule = 'landmark';
var expectedInternalState = {};

builder.disableRules(colorRule);
expectedInternalState[colorRule] = {
enabled: false
};
assert.deepEqual(builder._options.rules, expectedInternalState);

builder.disableRules([colorRule, landmarkRule]);
expectedInternalState[landmarkRule] = {
enabled: false
};
assert.deepEqual(builder._options.rules, expectedInternalState);

builder.disableRules(colorRule);
expectedInternalState = {
"color-contrast": {
enabled: false
}
};
assert.deepEqual(builder._options.rules, expectedInternalState);
});

it('should return itself', function () {
assert.instanceOf(new Builder().disableRules('color-contrast'), Builder);
});
});

describe('configure', function () {
it('should take a config object to customize aXe', function (done) {
var catsConfig = {
Expand Down

0 comments on commit 3833c59

Please sign in to comment.