pwa-helpers
Version:
Small helper methods or mixins to help you build web apps.
51 lines (44 loc) • 2.15 kB
TypeScript
/**
@license
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
import { ElementContext, RunOptions } from 'axe-core';
declare global {
namespace axe {
const run: typeof import('axe-core').run;
}
}
export interface AxeReportOptions extends RunOptions {
cleanup?: () => Promise<void>;
axeConfig?: RunOptions;
}
/**
This is an [axe-core](https://github.com/dequelabs/axe-core) reporter that returns an
Error containing every a11y violation for an element. Use this if you want to
include `axe-core` in automated Mocha tests, etc. Note that this helper does not
include `axe-core` for you; you must do this separately.
The `axeReport` function takes an optional second argument:
{cleanup: {...}, axeConfig: {...}}, where `cleanup` is a callback to be
called after the test is ran (so that you can remove the element from the DOM, etc)
and `axeConfig` are the optional extra config parameters to pass to axe.
Example (in a Mocha test):
import 'axe-core/axe.min.js';
import { axeReport } from 'pwa-helpers/axe-report.js';
describe('button', function() {
it('is accessible', function() {
const button = document.createElement('button');
button.textContent = 'click this'; // Test should fail without this line.
return axeReport(button);
// If you need to run any cleanup code after the test is run, you
// can use the `cleanup` object. For example,
// document.body.appendChild(button);
// return axeReport(el, { cleanup() { el.remove(); } });
});
});
*/
export declare function axeReport(dom: ElementContext, config?: AxeReportOptions): Promise<void>;