docbrown/app/javascript/listings/__tests__/ModalBackground.test.jsx
2020-06-25 18:04:01 -04:00

36 lines
1 KiB
JavaScript

import { h } from 'preact';
import { render } from '@testing-library/preact';
import { axe } from 'jest-axe';
import ModalBackground from '../components/ModalBackground';
describe('<ModalBackground />', () => {
const defaultProps = {
onClick: () => {
return 'onClick';
},
};
it('should have no a11y violations', async () => {
const { container } = render(<ModalBackground {...defaultProps} />);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
it('should render', () => {
const { queryByTestId } = render(<ModalBackground {...defaultProps} />);
expect(queryByTestId('listings-modal-background')).toBeDefined();
});
it('should call the onClick handler', () => {
const onClick = jest.fn();
const { getByTestId } = render(
<ModalBackground {...defaultProps} onClick={onClick} />,
);
const modalBackground = getByTestId('listings-modal-background');
modalBackground.click();
expect(onClick).toHaveBeenCalledTimes(1);
});
});