Skip to content

Instantly share code, notes, and snippets.

@crshmk
Last active February 9, 2021 14:28
Show Gist options
  • Save crshmk/9ba3682700cd25863238134db0e98a23 to your computer and use it in GitHub Desktop.
Save crshmk/9ba3682700cd25863238134db0e98a23 to your computer and use it in GitHub Desktop.
jest / react-testing-library / axe
import React from "react"
let App = () => (
<div>
<img data-testid="image" src="" />
<p>hi</p>
</div>
)
export default App
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()
})
})
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()
})
@crshmk
Copy link
Author

crshmk commented Feb 8, 2021

Screen Shot 2021-02-08 at 2 08 11 PM

@crshmk
Copy link
Author

crshmk commented Feb 9, 2021

disable rule with cli

axe www.deque.com --disable color-contrast

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