Last active
February 9, 2021 14:28
-
-
Save crshmk/9ba3682700cd25863238134db0e98a23 to your computer and use it in GitHub Desktop.
jest / react-testing-library / axe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
let App = () => ( | |
<div> | |
<img data-testid="image" src="" /> | |
<p>hi</p> | |
</div> | |
) | |
export default App |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { render } from '@testing-library/react'; | |
const { axe, toHaveNoViolations } = require('jest-axe') | |
expect.extend(toHaveNoViolations) | |
import App from '../' | |
describe('App', function() { | |
test('mounts', function() { | |
let { getByText } = render(<App />) | |
expect(getByText('hi')).toBeTruthy() | |
}) | |
test('accessibility', async function() { | |
let { container } = render(<App />) | |
let results = await axe(container) | |
expect(results).toHaveNoViolations() | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let axeConfig = { | |
impactLevels: ['critical'], | |
rules: { | |
'color-contrast': { enabled: false } | |
} | |
} | |
... | |
test('accessibility', async function() { | |
let { container } = render(<App />) | |
let results = await axe(container, axeConfig) | |
expect(results).toHaveNoViolations() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
disable rule with cli