Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: adds aXe test for <Officers />; resolves key bug #507

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions __tests__/components/LeadershipOfficers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import React from 'react';
import { act } from 'react-dom/test-utils';
import Officers from '../../components/LeadershipOfficers';
import data from '../../data';

expect.extend(toHaveNoViolations);

// TODO: consider lifting this mock globally
jest.mock('next/image', () => ({
__esModule: true,
default: (props) => {
// eslint-disable-next-line @next/next/no-img-element
return <img alt={props.alt} {...props} />;
},
}));

it('has no axe violations', async () => {
const { leadership } = data;

// this let / async construct is required since next/image rendering
// is a side effect that needs to be captured with async act
// see https://reactjs.org/docs/test-utils.html#act
let results;
await act(async () => {
const { container } = render(<Officers officers={leadership} />);
results = await axe(container);
});

expect(results).toHaveNoViolations();
});
2 changes: 1 addition & 1 deletion components/LeadershipOfficers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Officers(props){
<div className="grid-desktop-3">
{
props.officers.map(
officer => <Officer officer={officer} key={officer.image} />,
officer => <Officer officer={officer} key={officer.name + officer.position} />,
)
}
</div>
Expand Down