{"name":"jest-axe","version":"5.0.1","keywords":["jest","matcher","axe","accessibility","a11y"],"author":{"name":"Nick Colley"},"license":"MIT","_id":"jest-axe@5.0.1","maintainers":[{"name":"nickcolley","email":"nickcolley7@gmail.com"}],"homepage":"https://github.com/nickcolley/jest-axe#readme","bugs":{"url":"https://github.com/nickcolley/jest-axe/issues"},"dist":{"shasum":"26c43643b2e5f2bd4900c1ab36f8283635957a6e","tarball":"http://registry-npm.ywwl.com/jest-axe/download/jest-axe-5.0.1.tgz","fileCount":6,"integrity":"sha512-MMOWA6gT4pcZGbTLS8ZEqABH08Lnj5bInfLPpn9ADWX2wFF++odbbh8csmSfkwKjHaioVPzlCtIypAtxFDx/rw==","signatures":[{"sig":"MEUCIEhY9xFgdUVERj2yg+2Cvs5r0niz9OC1Az2WXJueVaEzAiEAnsz6zBlPgi7UD43OjhYTwmjM/DK4K+GyXVPUF79g9wc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21491,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJguJwTCRA9TVsSAnZWagAA+fEP/2FsBSQDHr+28a/l4283\nJ5dUzPTXe0uu8v2zZ+EbSupABQdFFRHqb6geBtdb9cu+2fW2dxRzXDrBcV3a\nAt1qMoPoZUma8GA9hXjXJ4g817Jj4TMaIXdeR5NLtKMYcvgxSAo/eV6fD+6g\nNL1FHIOpmyvMD3fIJJFfjCWVwNLmjjvhEtgIVnoWgeVRASQBsznx/OlPEjN5\n12pVZHBHvbxdmNnahlFmen7GK3B+6wMsSzNpCPEConx7IBWJywYJd7iIFX2t\n9Pf2f19RV0KM08Kwc1rSi3gV9dO2XEKGwqjT1SX6hewfUBQmgCAWsB11BGyk\npj/8pJqNSJZHFs6YIUuP8ylwatrX7uvi95yXjyFNIzcjygdwwKNJqDoYTqfk\n4YOYurD7vjni9xY9sqFbdL7X/+cbZ9QAdE1o1SdgQLbyY7g8z+o0bXIAXjBV\nSejncCzYyQmE2f+ZW8mgbIlbr85tgzSpin5J5r0/gT0n7pYrIX0PJkugS3sh\nZxG4KY8TLnUMVjl0qEqVWyGSaYXroJdJOrKvZPL6HQHTVzr7f8FULsayV5hR\n4HsTVt1ghi6CFeuWWTVs8cLDVElD9Jud71zfAED0aK2KkNLWe1JAEgN2s6lC\n6iMNEe1PGpvMibxfSpmxkGsZ7wzuzRuuXLlEJnq4VK3tsxPHfWKiNUaLCb3o\njRfx\r\n=lJ5h\r\n-----END PGP SIGNATURE-----\r\n","size":7019,"noattachment":false,"key":"/jest-axe/-/jest-axe-5.0.1.tgz"},"main":"index.js","engines":{"node":">= 10.0.0"},"gitHead":"0b4c6af31143f64386739b72b7a6c42c70a16b0d","scripts":{"test":"FORCE_COLOR=0 jest"},"_npmUser":{"name":"nickcolley","email":"nickcolley7@gmail.com"},"repository":{"url":"git+https://github.com/nickcolley/jest-axe.git","type":"git"},"_npmVersion":"6.14.10","description":"Custom Jest matcher for aXe for testing accessibility","directories":{},"_nodeVersion":"12.20.1","dependencies":{"chalk":"4.1.0","axe-core":"4.2.1","lodash.merge":"4.6.2","jest-matcher-utils":"27.0.2"},"_hasShrinkwrap":false,"devDependencies":{"vue":"2.6.12","jest":"26.6.2","react":"16.14.0","enzyme":"3.11.0","react-dom":"16.13.0","@vue/test-utils":"1.1.1","vue-server-renderer":"2.6.12","@testing-library/vue":"5.6.2","vue-template-compiler":"2.6.12","@testing-library/react":"11.2.7","@vue/server-test-utils":"1.1.1","enzyme-adapter-react-16":"1.15.5"},"_npmOperationalInternal":{"tmp":"tmp/jest-axe_5.0.1_1622711315599_0.6540986369656066","host":"s3://npm-registry-packages"},"readme":"# jest-axe\r\n\r\n[![npm version](https://img.shields.io/npm/v/jest-axe.svg)](http://npm.im/jest-axe)\r\n![node](https://img.shields.io/node/v/jest-axe)\r\n[![Repository CI Status](https://github.com/nickcolley/jest-axe/workflows/test/badge.svg)](https://github.com/nickcolley/jest-axe/actions?query=workflow%3Atest)\r\n\r\nCustom [Jest][Jest] matcher for [axe](https://github.com/dequelabs/axe-core) for testing accessibility\r\n\r\n## ⚠️✋ This project does not guarantee that what you build is accessible.\r\nThe GDS Accessibility team found that only [~30% of issues are found by automated testing](https://accessibility.blog.gov.uk/2017/02/24/what-we-found-when-we-tested-tools-on-the-worlds-least-accessible-webpage).\r\n\r\nTools like axe are similar to [code linters](https://en.wikipedia.org/wiki/Lint_%28software%29) such as [eslint](https://eslint.org/) or [stylelint](https://stylelint.io/): they can find common issues but cannot guarantee that what you build works for users.\r\n\r\nYou'll also need to:\r\n- test your interface with the [assistive technologies that real users use](https://www.gov.uk/service-manual/technology/testing-with-assistive-technologies#when-to-test) (see also [WebAIM's survey results](https://webaim.org/projects/screenreadersurvey8/#primary)).\r\n- include disabled people in user research.\r\n\r\n### Checks that do not work in jest-axe\r\n\r\nColor contrast checks do not work in JSDOM so are turned off in jest-axe.\r\n\r\n## Installation:\r\n```bash\r\nnpm install --save-dev jest jest-axe jest-environment-jsdom\r\n```\r\n\r\n[TypeScript](https://www.typescriptlang.org/) users can install the community maintained types package:\r\n\r\n```bash\r\nnpm install --save-dev @types/jest-axe\r\n```\r\n\r\n## Usage:\r\n\r\n```javascript\r\n/**\r\n * @jest-environment jsdom\r\n */\r\nconst { axe, toHaveNoViolations } = require('jest-axe')\r\n\r\nexpect.extend(toHaveNoViolations)\r\n\r\nit('should demonstrate this matcher`s usage', async () => {\r\n  const render = () => '<img src=\"#\"/>'\r\n\r\n  // pass anything that outputs html to axe\r\n  const html = render()\r\n\r\n  expect(await axe(html)).toHaveNoViolations()\r\n})\r\n```\r\n\r\n![Screenshot of the resulting output from the usage example](example-cli.png)\r\n\r\n> Note, you can also require `'jest-axe/extend-expect'` which will call `expect.extend` for you.\r\n> This is especially helpful when using the jest `setupFilesAfterEnv` configuration.\r\n\r\n### Testing React\r\n\r\n```javascript\r\nconst React = require('react')\r\nconst { render } =  require('react-dom')\r\nconst App = require('./app')\r\n\r\nconst { axe, toHaveNoViolations } = require('jest-axe')\r\nexpect.extend(toHaveNoViolations)\r\n\r\nit('should demonstrate this matcher`s usage with react', async () => {\r\n  render(<App/>, document.body)\r\n  const results = await axe(document.body)\r\n  expect(results).toHaveNoViolations()\r\n})\r\n```\r\n\r\n### Testing React with [React Testing Library](https://testing-library.com/docs/react-testing-library/intro)\r\n\r\n```javascript\r\nconst React = require('react')\r\nconst App = require('./app')\r\n\r\nconst { render } = require('@testing-library/react')\r\nconst { axe, toHaveNoViolations } = require('jest-axe')\r\nexpect.extend(toHaveNoViolations)\r\n\r\nit('should demonstrate this matcher`s usage with react testing library', async () => {\r\n  const { container } = render(<App/>)\r\n  const results = await axe(container)\r\n  \r\n  expect(results).toHaveNoViolations()\r\n})\r\n```\r\n\r\n> Note: If you're using `react testing library` <9.0.0 you should be using the\r\n> [`cleanup`](https://testing-library.com/docs/react-testing-library/api#cleanup) method. This method removes the rendered application from the DOM and ensures a clean HTML Document for further testing.\r\n\r\nIf you're using [React Portals](https://reactjs.org/docs/portals.html), use the [`baseElement`](https://testing-library.com/docs/react-testing-library/api#baseelement) instead of `container`:\r\n\r\n```js\r\nit('should work with React Portals as well', async () => {\r\n  const { baseElement } = render(<App/>)\r\n  const results = await axe(baseElement)\r\n  \r\n  expect(results).toHaveNoViolations()\r\n})\r\n```\r\n\r\n### Testing Vue with [Vue Test Utils](https://vue-test-utils.vuejs.org/)\r\n\r\n```javascript\r\nconst App = require('./App.vue')\r\n\r\nconst { mount } = require('@vue/test-utils')\r\nconst { axe, toHaveNoViolations } = require('jest-axe')\r\nexpect.extend(toHaveNoViolations)\r\n\r\nit('should demonstrate this matcher`s usage with vue test utils', async () => {\r\n  const wrapper = mount(Image)\r\n  const results = await axe(wrapper.element)\r\n\r\n  expect(results).toHaveNoViolations()\r\n})\r\n```\r\n\r\n### Testing Vue with [Vue Testing Library](https://testing-library.com/docs/vue-testing-library/intro)\r\n\r\n```javascript\r\nconst App = require('./app')\r\n\r\nconst { render } = require('@testing-library/vue')\r\nconst { axe, toHaveNoViolations } = require('jest-axe')\r\nexpect.extend(toHaveNoViolations)\r\n\r\nit('should demonstrate this matcher`s usage with react testing library', async () => {\r\n  const { container } = render(<App/>)\r\n  const results = await axe(container)\r\n  \r\n  expect(results).toHaveNoViolations()\r\n})\r\n```\r\n> Note: If you're using `vue testing library` <3.0.0 you should be using the\r\n> [`cleanup`](https://testing-library.com/docs/vue-testing-library/api#cleanup) method. This method removes the rendered application from the DOM and ensures a clean HTML Document for further testing.\r\n\r\n### Testing Angular with [Nx](https://nx.dev/)\r\n\r\n```typescript\r\nimport { ComponentFixture, TestBed } from \"@angular/core/testing\";\r\nimport { axe } from \"jest-axe\";\r\n\r\nimport { SomeComponent } from \"./some.component\";\r\n\r\ndescribe(\"SomeComponent\", () => {\r\n  let fixture: ComponentFixture<SomeComponent>;\r\n\r\n  beforeEach(() => {\r\n    TestBed.configureTestingModule({\r\n      declarations: [SomeComponent],\r\n    });\r\n\r\n    fixture = TestBed.createComponent(SomeComponent);\r\n  });\r\n\r\n  it(\"should create\", async () => {\r\n    const results = await axe(fixture.nativeElement);\r\n    expect(results).toHaveNoViolations();\r\n  });\r\n});\r\n```\r\n\r\n> Note: You may need to extend jest by importing `jest-axe/extend-expect` at `test-setup.ts`\r\n\r\n### Usage with jest.useFakeTimers() or mocking setTimeout\r\n\r\n> thrown: \"Exceeded timeout of 5000 ms for a test.\r\n> Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.\"\r\n\r\naXe core does not work when timers (setTimeout) are mocked. When using `jest.useFakeTimers()` aXe core will timeout often causing failing tests.\r\n\r\nWe recommend renabling the timers temporarily for aXe:\r\n\r\n```javascript\r\njest.useRealTimers();\r\nconst results = await axe(wrapper.element);\r\njest.useFakeTimers();\r\n```\r\n\r\n### Axe configuration\r\n\r\nThe `axe` function allows options to be set with the [same options as documented in axe-core](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#options-parameter):\r\n\r\n```javascript\r\nconst { axe, toHaveNoViolations } = require('jest-axe')\r\n\r\nexpect.extend(toHaveNoViolations)\r\n\r\nit('should demonstrate this matcher`s usage with a custom config', async () => {\r\n  const render = () => `\r\n    <div>\r\n      <img src=\"#\"/>\r\n    </div>\r\n  `\r\n\r\n  // pass anything that outputs html to axe\r\n  const html = render()\r\n\r\n  const results = await axe(html, {\r\n    rules: {\r\n      // for demonstration only, don't disable rules that need fixing.\r\n      'image-alt': { enabled: false }\r\n    }\r\n  })\r\n\r\n  expect(results).toHaveNoViolations()\r\n})\r\n```\r\n\r\n### Testing isolated components\r\n\r\n> All page content must be contained by landmarks (region)\r\n\r\nWhen testing with aXe sometimes it assumes you are testing a page. This then results in unexpected violations for landmarks for testing isolation components.\r\n\r\nYou can disable this behaviour with the `region` rule:\r\n\r\n```javascript\r\nconst { configureAxe } = require('jest-axe')\r\n\r\nconst axe = configureAxe({\r\n  rules: {\r\n    // disable landmark rules when testing isolated components.\r\n    'region': { enabled: false }\r\n  }\r\n})\r\n```\r\n\r\n## Setting global configuration\r\n\r\nIf you find yourself repeating the same options multiple times, you can export a version of the `axe` function with defaults set.\r\n\r\nNote: You can still pass additional options to this new instance; they will be merged with the defaults.\r\n\r\nThis could be done in [Jest's setup step](https://jestjs.io/docs/en/setup-teardown)\r\n\r\n```javascript\r\n// Global helper file (axe-helper.js)\r\nconst { configureAxe } = require('jest-axe')\r\n\r\nconst axe = configureAxe({\r\n  rules: {\r\n    // for demonstration only, don't disable rules that need fixing.\r\n    'image-alt': { enabled: false }\r\n  }\r\n})\r\n\r\nmodule.exports = axe\r\n```\r\n\r\n```javascript\r\n// Individual test file (test.js)\r\nconst { toHaveNoViolations } = require('jest-axe')\r\nconst axe = require('./axe-helper.js')\r\n\r\nexpect.extend(toHaveNoViolations)\r\n\r\nit('should demonstrate this matcher`s usage with a default config', async () => {\r\n  const render = () => `\r\n    <div>\r\n      <img src=\"#\"/>\r\n    </div>\r\n  `\r\n\r\n  // pass anything that outputs html to axe\r\n  const html = render()\r\n\r\n  expect(await axe(html)).toHaveNoViolations()\r\n})\r\n```\r\n\r\n### Setting custom rules and checks.\r\n\r\nThe configuration object passed to `configureAxe`, accepts a `globalOptions` property to configure the format of the data used by axe and to add custom checks and rules. The property value is the same as the parameter passed to [axe.configure](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#parameters-1). \r\n\r\n```javascript\r\n// Global helper file (axe-helper.js)\r\nconst { configureAxe } = require('jest-axe')\r\n\r\nconst axe = configureAxe({\r\n  globalOptions: {\r\n    checks: [/* custom checks definitions */]\r\n  },\r\n  // ...\r\n})\r\n\r\nmodule.exports = axe\r\n```\r\n\r\n### Setting the level of user impact.\r\n\r\nAn array which defines which [impact](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md) level should be considered. This ensures that only violations with a specific impact on the user are considered. The level of impact can be \"minor\", \"moderate\", \"serious\", or \"critical\".\r\n\r\n```javascript\r\n// Global helper file (axe-helper.js)\r\nconst { configureAxe } = require('jest-axe')\r\n\r\nconst axe = configureAxe({\r\n  impactLevels: ['critical'],\r\n  // ...\r\n})\r\n\r\nmodule.exports = axe\r\n```\r\n\r\nRefer to [Developing Axe-core Rules](https://github.com/dequelabs/axe-core/blob/master/doc/rule-development.md) for instructions on how to develop custom rules and checks.\r\n\r\n## Thanks\r\n- [Jest][Jest] for the great test runner that allows extending matchers.\r\n- [axe](https://www.deque.com/axe/) for the wonderful axe-core that makes it so easy to do this.\r\n- Government Digital Service for making coding in the open the default.\r\n  - GOV.UK Publishing Frontend team who published the [basis of the aXe reporter](https://github.com/alphagov/govuk_publishing_components/blob/581c22c9d35d85d5d985571d007f6397a4399f4c/spec/javascripts/govuk_publishing_components/AccessibilityTestSpec.js)\r\n- [jest-image-snapshot](https://github.com/americanexpress/jest-image-snapshot) for inspiration on README and repo setup\r\n\r\n[Jest]: https://jestjs.io/\r\n","publish_time":1622711315778,"_cnpm_publish_time":1622711315778,"dist-tags":{"latest":"11.0.0"}}