diff --git a/README.md b/README.md index 21354f7..0bbe800 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/index.js b/lib/index.js index fdb550c..edd5cd6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 diff --git a/test/unit/index.js b/test/unit/index.js index 1cacfe7..3e2e60a 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -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 = {