{"name":"jest-axe","version":"3.0.0","keywords":["jest","matcher","axe","accessibility","a11y"],"author":{"name":"Nick Colley"},"license":"MIT","_id":"jest-axe@3.0.0","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":"c5704fafb0a7253d261f6cc3e85121d30102733d","tarball":"http://registry-npm.ywwl.com/jest-axe/download/jest-axe-3.0.0.tgz","fileCount":5,"integrity":"sha512-LG1F0J9+kDiVSS+d9heCFEgayw+E0zYc4nIM05R19rWEHZ+uJGADW9KTdDUzYjuW7lcmUISRIZflVHXMpSlxog==","signatures":[{"sig":"MEQCIGMbfLfUuKC1lIBBd6joUiPOPFeV0t/iaqDIh2pd5FLZAiBc0e7qniF46ehZJ8Ue1FwgJ5bY7zDn0Y7W3kz3DeVKjQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":11527,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbC05PCRA9TVsSAnZWagAAZwYP/0n8dZ3dk7Un/eN6+AAj\nhVhYuHWkLPXoM4O1D2lwOGdmVdOhNpxLJxC0A52B8xzvSxDBNW6kZAaXvqJT\nbwfJY00zI2YnvZuQ+veUX3zpe64tSFj4dme47k+/rowsT3Kt4N+5/X7L0CkS\npuisJjh0G+KcziNwxhadNmVcu+pWOb8WkUMYR5q7s3xYkbNjaSn73uluoJxX\nmYK/kJSYcWG3bNw/xFdA9m4TX2BuFZ9kvYz3e5Cidsb5dUxsPL3onvtg56FQ\n9GY/5I9vypd5xPRTG6m972YDytvlCgvmG3ZcNfdLATeO44pzrDWtnFdEZVj5\n+awmJS3HxKBlzpogIDXhUMpDNX9HDYWWmoodGQHwP/bl9QM3p7ZEH6A/Aw+z\nRgJwK7poU3vdeE7fCaC1QX9t1djLdjH9li6pc3wvlMhby7W6Z61TCcBKraKX\nkDyekZp44T8jYeXjIysh++TcnHVHw+71ETafZnyyNMkYz6MwLBSoIplymYNA\nV2tOUnO7k4zKIO0Sml+Ivci4zhYThNVx5TsFFanatXHak1YmQ7cn3f2oRrUQ\njagBLj1JVmBwvaX4UqOplXdqEMjV5mpNVYHAS2gep0cyEujPPLQse6Kx/Y4m\n5ltTfGeJ/931fAexYYZ0ZkxmfGdbZOpfyE+4WWejzbc67EnzIfv2JPcOsgv1\nKwZ7\r\n=kEYT\r\n-----END PGP SIGNATURE-----\r\n","size":4643,"noattachment":false,"key":"/jest-axe/-/jest-axe-3.0.0.tgz"},"jest":{"transform":{"^.+\\.js$":"async-to-gen"}},"main":"index.js","_from":".","files":["index.js"],"_shasum":"c5704fafb0a7253d261f6cc3e85121d30102733d","engines":{"node":">= 6.0.0"},"gitHead":"86fc06603b6548b12cf57d2a54b90ddeb1f71499","scripts":{"test":"jest"},"_npmUser":{"name":"nickcolley","email":"nickcolley7@gmail.com"},"repository":{"url":"git+https://github.com/nickcolley/jest-axe.git","type":"git"},"_npmVersion":"3.10.10","description":"Custom Jest matcher for aXe for testing accessibility","directories":{},"_nodeVersion":"6.14.2","dependencies":{"axe-core":"3.0.2","lodash.merge":"4.6.1","jest-matcher-utils":"23.0.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"23.0.1","react":"16.4.0","react-dom":"16.4.0","async-to-gen":"^1.4.0"},"_npmOperationalInternal":{"tmp":"tmp/jest-axe_3.0.0_1527467597529_0.44081137163106576","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":1527467597591,"_cnpm_publish_time":1527467597591,"dist-tags":{"latest":"11.0.0"}}