ember-axe

The future of accessibility testing in Ember

Usage no npm install needed!

<script type="module">
  import emberAxe from 'https://cdn.skypack.dev/ember-axe';
</script>

README

ember-axe

Build Status NPM Version

Ember Axe is a wrapper around Deque Labs' axe-core accessibility testing engine. It automatically integrates into your testing environment by running during the afterRender step in the run loop during any acceptance tests.

If you're using Ember 1.13.0 or above, it also integrates into your development workflow by running during a component's didRender phase in non-production environments. This gives you instant feedback on if your component's are accessible in any given state.

Future Plans

Now that your components and acceptance tests can self-audit, the next step going forward is to give helpful and meaningful feedback to developers. This means easily highlighting areas with violations and giving suggestions on how to fix and improve them. Additionally, work will be done to tackle Ember-specific accessibility issues, such as identifying actions on inaccessible elements.

Usage In Testing

Usage inside tests right now is super simple, just install the addon via:

ember install ember-axe

That's it! It will automatically begin running during acceptance tests. It also injects the axe object globally during development so you can run tests while developing your application as well.

Note: any tests run with Ember Axe will adjust the testing container to occupy the entire screen. This is to simulate the actual application environment, as browsers adjust styles at small sizes for accessibility reasons. It will reset itself at the conclusion of testing though.

Disable/Enable Tests

By default, the axe-core tests only run during acceptance tests. In order to enable them for other tests, simply run the following at the beginning of your testing module:

axe.ember.turnAxeOn();

On the flip side, if you want to turn tests off, simply use:

axe.ember.turnAxeOff();

Options

You can pass specific options to be used during a11yCheck by setting them on a global testOptions property:

axe.ember.testOptions = {
  runOnly: {
    type: "tag",
    values: ["wcag2a"]
  }
};

You can see the available options in the axe-core repo.

Note: the options will stay set, until set to something different.

Usage In Development

Usage in development is restricted to applications using Ember 1.13 and up as it relies on the didRender hook of a component's life-cycle (a feature only available in versions of Ember with the Glimmer rendering engine).

That said, setup for development is as simple as it is for testing, simply install the addon.

By default, Ember Axe will audit a component for accessibility each time it is rendered. This ensures that the component is still accessible even after state changes, and since the checks are scoped to a component's element, it means that any state change propagated downwards is also caught.

Component Hooks

Since development is not a uniform experience, Ember Axe provides several hooks to help stay out of the way.

Note: these are all undefined by default.

Defining a custom callback

If you feel the logging of violations is poor or you just want to see the entire results of a component's audit, you can define a custom callback. The callback receives the results of the a11yCheck audit that is scoped to the component's element. Simply set it as axeCallback on the component in question:

axeCallback(results) {
  // do stuff with results
}

Setting options for the audit

As with testing, if you need to set custom auditing options for a component, you can do so easily. Simply set a value for the axeOptions property value:

axeOptions: { /* a11yCheck options */ }

Turning the audit off

Lastly, if you really find the audits to be cramping development, you can turn them off via a simple boolean switch:

turnAuditOff: true