|
| 1 | +import { render } from '@testing-library/react'; |
| 2 | +import { axe, toHaveNoViolations } from 'jest-axe'; |
| 3 | +import React from 'react'; |
| 4 | +import { act } from 'react-dom/test-utils'; |
| 5 | +import SocialMedia from '../../components/SocialMedia'; |
| 6 | + |
| 7 | +expect.extend(toHaveNoViolations); |
| 8 | + |
| 9 | +describe('SocialMedia, dark text (default)', () => { |
| 10 | + it('has no axe violations', async () => { |
| 11 | + // this let / async construct is required since next/image rendering |
| 12 | + // is a side effect that needs to be captured with async act |
| 13 | + // see https://reactjs.org/docs/test-utils.html#act |
| 14 | + let results; |
| 15 | + await act(async () => { |
| 16 | + const { container } = render(<SocialMedia />); |
| 17 | + results = await axe(container); |
| 18 | + }); |
| 19 | + expect(results).toHaveNoViolations(); |
| 20 | + }); |
| 21 | +}); |
| 22 | + |
| 23 | +describe('SocialMedia, light text', () => { |
| 24 | + it('has no axe violations', async () => { |
| 25 | + // this let / async construct is required since next/image rendering |
| 26 | + // is a side effect that needs to be captured with async act |
| 27 | + // see https://reactjs.org/docs/test-utils.html#act |
| 28 | + let results; |
| 29 | + await act(async () => { |
| 30 | + const { container } = render(<SocialMedia type="light" />); |
| 31 | + results = await axe(container); |
| 32 | + }); |
| 33 | + expect(results).toHaveNoViolations(); |
| 34 | + }); |
| 35 | +}); |
0 commit comments