Irina Glushko 2389e7160b HW1 done | 3 years ago | |
---|---|---|
.. | ||
README.md | 3 years ago | |
link.js | 3 years ago | |
link.test.js | 3 years ago | |
package.json | 3 years ago | |
test-helpers.js | 3 years ago |
This example demonstrates how to use axe to test React components using the Jest unit testing framework.
The unit test is in link.test.js
, and has one test cases, showing how to run
axe-core in Jest (using JSDOM and Enzyme).
doc/examples/jest_react
directorynpm install
to install dependenciesdoc/examples/jest_react
directorynpm test
to run JestYou should see output indicating that the tests ran successfully, with zero failures.
Note: to work better with JSDOM (which has limited support for necessary DOM APIs), the color-contrast and link-in-text-block rules have been disabled in this example. You can test for these rules more reliably using full browser DOM integration testing using axe-webdriverjs.
This example can be modified to test components in other test frameworks as well. To use axe-core with JSDOM (Like Jest does), you will need to ensure that JSDOM variables are made available on the global object. An easy way to do this is to use jsdom-global.
For example, when running Mocha, you should require jsdom-global/register
. The command for this is as follows:
mocha *.test.js --require jsdom-global/register
Axe-core is very fast for what it does, but when testing larger components, it may take a few seconds to complete. This is because axe will be running thousands of tests in a single call. When testing composite components, you may have to increase the timeout setting.