Skip to content

Instantly share code, notes, and snippets.

@crshmk
Last active February 9, 2021 16:13
Show Gist options
  • Save crshmk/d7f1b1836e858adcddcaba0c27145518 to your computer and use it in GitHub Desktop.
Save crshmk/d7f1b1836e858adcddcaba0c27145518 to your computer and use it in GitHub Desktop.
Wrapper for jest-axe
import React from "react"
let App = () => (
<div>
<img src="" />
<p>hi</p>
</div>
)
export default App
import testAccessibility from './testAccessibility'
import App from '../'
describe('App', function() {
test('accessibility', async function() {
await testAccessibility(App)
})
})
import React from 'react'
import { render } from '@testing-library/react';
const { axe, configureAxe, toHaveNoViolations } = require('jest-axe')
expect.extend(toHaveNoViolations)
let config = {
impactLevels: ['critical'],
rules: {
'color-contrast': { enabled: false }
}
}
async function testAccessibility(El) {
let { container } = render(<El />)
let results = await axe(container, config)
return expect(results).toHaveNoViolations()
}
export default testAccessibility
@crshmk
Copy link
Author

crshmk commented Feb 9, 2021

Screen Shot 2021-02-09 at 10 07 18 AM

@crshmk
Copy link
Author

crshmk commented Feb 9, 2021

Note the async requirement in the test; omitting this will result in a false positive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment