Migrated UseExistingIfFoundInfoIcon test from enzyme to react testing library

This commit is contained in:
Alejandro Celaya
2022-05-02 18:54:19 +02:00
parent e837ee5225
commit c00aaa9018
3 changed files with 9 additions and 21 deletions

View File

@@ -1,22 +1,12 @@
import { mount, ReactWrapper } from 'enzyme';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Modal } from 'reactstrap';
import UseExistingIfFoundInfoIcon from '../../src/short-urls/UseExistingIfFoundInfoIcon';
import { fireEvent, render, screen } from '@testing-library/react';
import { UseExistingIfFoundInfoIcon } from '../../src/short-urls/UseExistingIfFoundInfoIcon';
describe('<UseExistingIfFoundInfoIcon />', () => {
let wrapped: ReactWrapper;
it('shows modal when icon is clicked', async () => {
render(<UseExistingIfFoundInfoIcon />);
beforeEach(() => {
wrapped = mount(<UseExistingIfFoundInfoIcon />);
});
afterEach(() => wrapped.unmount());
it('shows modal when icon is clicked', () => {
const icon = wrapped.find(FontAwesomeIcon);
expect(wrapped.find(Modal).prop('isOpen')).toEqual(false);
icon.simulate('click');
expect(wrapped.find(Modal).prop('isOpen')).toEqual(true);
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
fireEvent.click(screen.getByTitle('What does this mean?').firstChild as Node);
expect(await screen.findByRole('dialog')).toBeInTheDocument();
});
});