{"_id":"jest-axe@11.0.0","bugs":{"url":"https://github.com/NickColley/jest-axe/issues"},"dist":{"shasum":"e133b83188fdd393f699b9b186b41adf8f93bd29","tarball":"http://registry-npm.ywwl.com/jest-axe/download/jest-axe-11.0.0.tgz","integrity":"sha512-JuLD/QzqDn5QxpFUMkbmf55GiI+sdutpryRD//rIRuyEefYAuMfQbQZ53TsNtZXKV3rjgfD4KKTKPY+2Ga1mGw==","fileCount":5,"unpackedSize":20249,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/jest-axe@11.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD1veVw2Qdb6qT1KNa5UhEdNMlYJWm8tDp+9x9wiALfjgIgJW/Rd6z6Zu/itKZmBV9R4KogkhhV8rDmEXi+xBndkW8="}],"size":6819,"noattachment":false,"key":"/jest-axe/-/jest-axe-11.0.0.tgz"},"jest":{"testEnvironment":"jsdom","testEnvironmentOptions":{"customExportConditions":["node","node-addons"]}},"main":"index.js","name":"jest-axe","author":{"name":"Nick Colley"},"engines":{"node":">= 18.0.0"},"gitHead":"399ae41cdf4f61b168dd6f7d5956c2899e40d015","license":"MIT","scripts":{"jest":"FORCE_COLOR=0 jest","lint":"npx @biomejs/biome check","test":"npm run lint && npm run jest"},"version":"11.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:dff6c287-db22-4c51-a673-c751c083b5e5"},"approver":{"name":"nickcolley","email":"nickcolley7@gmail.com"}},"homepage":"https://github.com/NickColley/jest-axe#readme","keywords":["jest","matcher","axe","accessibility","a11y"],"repository":{"url":"git+https://github.com/NickColley/jest-axe.git","type":"git"},"_npmVersion":"12.0.1","description":"Custom Jest matcher for aXe for testing accessibility","directories":{},"maintainers":[{"name":"nickcolley","email":"nickcolley7@gmail.com"}],"_nodeVersion":"24.18.0","dependencies":{"chalk":"4.1.2","axe-core":"4.12.1","lodash.merge":"4.6.2","jest-matcher-utils":"30.4.1"},"devDependencies":{"vue":"^3.5.40","jest":"^30.4.2","react":"^19.2.8","react-dom":"^19.2.8","@biomejs/biome":"2.5.5","@vue/test-utils":"^2.4.11","@testing-library/vue":"^8.1.0","@testing-library/react":"^16.3.2","jest-environment-jsdom":"^30.4.1"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jest-axe_11.0.0_1785092895873_0.45380369803018294"},"_hasShrinkwrap":false,"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 around [~30% of access barriers are missed 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":1785092895954,"_cnpm_publish_time":1785092895954,"dist-tags":{"latest":"11.0.0"}}