{"name":"jest-axe","version":"2.1.2","keywords":["jest","matcher","axe","accessibility","a11y"],"author":{"name":"Nick Colley"},"license":"MIT","_id":"jest-axe@2.1.2","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":"e02eeaccc25ec27a91b734a13b1ff86fc0e8ae7c","tarball":"http://registry-npm.ywwl.com/jest-axe/download/jest-axe-2.1.2.tgz","fileCount":10,"integrity":"sha512-FZ7pIRhKH3UaizMz+bMPc2mMH/gUtm/KgRQ3kPcBWvxfhNHCNr9aJ+FM87UyeL/+qSCmbpgMt8p8BD2A/YUbEg==","signatures":[{"sig":"MEUCIEgbxGMGHvaPchjCBzZQev5K2s84hjlSl2oU78ql5Js4AiEAzmgkmcUcdUgIDKGKZjTq/Old/+bd0Sk/SbX7wSRulgE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":113466,"size":89527,"noattachment":false,"key":"/jest-axe/-/jest-axe-2.1.2.tgz"},"main":"index.js","engines":{"node":">= 8.9.4"},"gitHead":"b33a239ed451ac7c8f17478910b14cfc2554b070","scripts":{"test":"standard && jest"},"_npmUser":{"name":"nickcolley","email":"nickcolley7@gmail.com"},"repository":{"url":"git+https://github.com/nickcolley/jest-axe.git","type":"git"},"_npmVersion":"5.6.0","description":"Custom Jest matcher for aXe for testing accessibility","directories":{},"_nodeVersion":"8.9.4","dependencies":{"axe-core":"^2.6.1","lodash.merge":"^4.6.1","jest-matcher-utils":"^22.2.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^22.2.2","react":"^16.2.0","standard":"^10.0.3","react-dom":"^16.2.0"},"_npmOperationalInternal":{"tmp":"tmp/jest-axe_2.1.2_1518701681603_0.6716591153327556","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":1518701682519,"_cnpm_publish_time":1518701682519,"dist-tags":{"latest":"11.0.0"}}