Browse Source
As proposed in #22343, the components can be automatically validated for accessibility. This adds a test helper that runs Axe to check for accessibility violations.pull/33136/head
Stef Schenkelaars
3 years ago
6 changed files with 24 additions and 0 deletions
@ -1,5 +1,7 @@ |
|||
import { toHaveNoViolations } from 'jest-axe'; |
|||
import toMatchRenderedSnapshot from './matchers/rendered-snapshot'; |
|||
|
|||
expect.extend(toHaveNoViolations); |
|||
expect.extend({ |
|||
toMatchRenderedSnapshot, |
|||
}); |
|||
|
@ -0,0 +1,15 @@ |
|||
import React from 'react'; |
|||
import { mount } from 'enzyme'; |
|||
import { axe } from 'jest-axe'; |
|||
|
|||
// eslint-disable-next-line jest/no-export
|
|||
export default function accessibilityTest(Component: React.ComponentType) { |
|||
describe(`accessibility`, () => { |
|||
it(`component does not have any violations`, async () => { |
|||
jest.useRealTimers(); |
|||
const wrapper = mount(<Component />); |
|||
const results = await axe(wrapper.getDOMNode()); |
|||
expect(results).toHaveNoViolations(); |
|||
}); |
|||
}); |
|||
} |
@ -1,5 +1,6 @@ |
|||
declare namespace jest { |
|||
interface Matchers<R> { |
|||
toMatchRenderedSnapshot(): R; |
|||
toHaveNoViolations(): R; |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue