Skip to content

Commit

Permalink
Merge branch 'accessibility-tests' of https://github.com/StefSchenkel…
Browse files Browse the repository at this point in the history
…aars/ant-design into StefSchenkelaars-accessibility-tests
  • Loading branch information
afc163 committed Dec 3, 2021
2 parents e0c777d + 98e36aa commit 46e700f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/affix/__tests__/Affix.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Affix, { AffixProps, AffixState } from '..';
import { getObserverEntities } from '../utils';
import Button from '../../button';
import rtlTest from '../../../tests/shared/rtlTest';
import accessibilityTest from '../../../tests/shared/accessibilityTest';
import { sleep } from '../../../tests/utils';

const events: Partial<Record<keyof HTMLElementEventMap, (ev: Partial<Event>) => void>> = {};
Expand Down Expand Up @@ -53,6 +54,7 @@ class AffixMounter extends React.Component<{

describe('Affix Render', () => {
rtlTest(Affix);
accessibilityTest(Affix);

const domMock = jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect');
let affixMounterWrapper: ReactWrapper<unknown, unknown, AffixMounter>;
Expand Down
2 changes: 2 additions & 0 deletions components/alert/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import Button from '../../button';
import Tooltip from '../../tooltip';
import Popconfirm from '../../popconfirm';
import rtlTest from '../../../tests/shared/rtlTest';
import accessibilityTest from '../../../tests/shared/accessibilityTest';
import { sleep } from '../../../tests/utils';

const { ErrorBoundary } = Alert;

describe('Alert', () => {
rtlTest(Alert);
accessibilityTest(Alert);

beforeAll(() => {
jest.useFakeTimers();
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
"@types/enzyme": "^3.10.5",
"@types/gtag.js": "^0.0.8",
"@types/jest": "^27.0.0",
"@types/jest-axe": "^3.5.3",
"@types/jest-environment-puppeteer": "^4.4.0",
"@types/jest-image-snapshot": "^4.1.0",
"@types/lodash": "^4.14.139",
Expand Down Expand Up @@ -225,6 +226,7 @@
"intersection-observer": "^0.12.0",
"isomorphic-fetch": "^3.0.0",
"jest": "^27.0.3",
"jest-axe": "^5.0.1",
"jest-image-snapshot": "^4.5.1",
"jest-puppeteer": "^6.0.0",
"jquery": "^3.4.1",
Expand Down
2 changes: 2 additions & 0 deletions tests/setupAfterEnv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { toHaveNoViolations } from 'jest-axe';
import toMatchRenderedSnapshot from './matchers/rendered-snapshot';

expect.extend(toHaveNoViolations);
expect.extend({
toMatchRenderedSnapshot,
});
15 changes: 15 additions & 0 deletions tests/shared/accessibilityTest.tsx
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions typings/jest.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare namespace jest {
interface Matchers<R> {
toMatchRenderedSnapshot(): R;
toHaveNoViolations(): R;
}
}

0 comments on commit 46e700f

Please sign in to comment.