axe-core
Version:
Accessibility engine for automated Web UI testing
111 lines (103 loc) • 2.61 kB
text/typescript
import * as axe from '../../axe'
var context:any = document
var $fixture:any = {}
axe.run(context, {}, (error: Error, results: axe.AxeResults) => {
if (error) {
console.log(error);
}
console.log(results.passes.length);
console.log(results.incomplete.length);
console.log(results.inapplicable.length);
console.log(results.violations.length);
console.log(results.violations[0].nodes[0].failureSummary)
});
axe.run().then(function(done:any) {
done();
});
// additional configuration options
axe.run(context, {iframes: false, selectors: false, elementRef: false},
(error: Error, results: axe.AxeResults) => {
console.log(error || results.passes.length);
});
// axe.run include/exclude
axe.run({include: [['#id1'], ['#id2']]}, {}, (error: Error, results: axe.AxeResults) => {
console.log(error || results)
})
axe.run({exclude: [$fixture[0]]}, {}, (error: Error, results: axe.AxeResults) => {
console.log(error || results)
})
// additional configuration options
axe.run(context, {iframes: false, selectors: false, elementRef: false},
(error: Error, results: axe.AxeResults) => {
console.log(error || results.passes.length);
});
var tagConfigRunOnly: axe.RunOnly = {
type: 'tag',
values: ['wcag2a']
}
var tagConfig = {
runOnly: tagConfigRunOnly
}
axe.run(context, tagConfig, (error: Error, results: axe.AxeResults) => {
console.log(error || results)
})
var includeExcludeTagsRunOnly: axe.RunOnly = {
type: 'tags',
values: {
include: ['wcag2a', 'wcag2aa'],
exclude: ['experimental']
}
}
var includeExcludeTagsConfig = {
runOnly: includeExcludeTagsRunOnly
}
axe.run(context, includeExcludeTagsConfig, (error: Error, results: axe.AxeResults) => {
console.log(error || results)
})
var someRulesConfig = {
rules: {
"color-contrast": {enabled: 'false'},
"heading-order": {enabled: 'true'}
}
}
axe.run(context, someRulesConfig, (error: Error, results: axe.AxeResults) => {
console.log(error || results)
})
// axe.configure
var spec: axe.Spec = {
branding: {
brand: 'foo',
application: 'bar'
},
reporter: 'v1',
checks: [{
id: 'custom-check',
evaluate: function() {
return true
}
}],
rules: [{
id: 'custom-rule',
any: ['custom-check']
}]
}
axe.configure(spec)
var source = axe.source;
axe.reset()
axe.getRules(['wcag2aa'])
typeof axe.getRules() === 'object'
// Plugins
var pluginSrc: axe.AxePlugin = {
id: 'doStuff',
run: (data:any, callback:Function) => {
callback()
},
commands: [{
id: 'run-doStuff',
callback: (data:any, callback:Function) => {
axe.plugins['doStuff'].run(data, callback)
}
}]
}
axe.registerPlugin(pluginSrc)
axe.cleanup()