Created
December 2, 2020 12:23
-
-
Save LeeCheneler/6eb7eae2a8233b51c3970e225604ff24 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "@testing-library/jest-dom/extend-expect"; | |
| import { cleanup } from "@testing-library/react"; | |
| import { axe, toHaveNoViolations } from "jest-axe"; | |
| // stop RTL from cleaning up after itself so we can assert on DOM after tests with aXe | |
| process.env.RTL_SKIP_AUTO_CLEANUP = "true"; | |
| // configure aXe | |
| expect.extend(toHaveNoViolations); | |
| afterEach(async () => { | |
| try { | |
| // if something has been rendered then we should assert it is accessible | |
| if (document.body.childNodes.length > 0) { | |
| expect(await axe(document.body)).toHaveNoViolations(); | |
| } | |
| } finally { | |
| // always cleanup the DOM | |
| cleanup(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment