mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-11 02:37:22 +03:00
Migrated ServerForm test to react testing library
This commit is contained in:
parent
e46506b264
commit
cd1a926292
1 changed files with 10 additions and 16 deletions
|
@ -1,30 +1,24 @@
|
||||||
import { shallow, ShallowWrapper } from 'enzyme';
|
import { fireEvent, render, screen } from '@testing-library/react';
|
||||||
import { ServerForm } from '../../../src/servers/helpers/ServerForm';
|
import { ServerForm } from '../../../src/servers/helpers/ServerForm';
|
||||||
import { InputFormGroup } from '../../../src/utils/forms/InputFormGroup';
|
|
||||||
|
|
||||||
describe('<ServerForm />', () => {
|
describe('<ServerForm />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
|
||||||
const onSubmit = jest.fn();
|
const onSubmit = jest.fn();
|
||||||
|
const setUp = () => render(<ServerForm onSubmit={onSubmit}>Something</ServerForm>);
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
wrapper = shallow(<ServerForm onSubmit={onSubmit}><span>Something</span></ServerForm>);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => wrapper?.unmount());
|
|
||||||
afterEach(jest.resetAllMocks);
|
afterEach(jest.resetAllMocks);
|
||||||
|
|
||||||
it('renders components', () => {
|
it('renders components', () => {
|
||||||
expect(wrapper.find(InputFormGroup)).toHaveLength(3);
|
setUp();
|
||||||
expect(wrapper.find('span')).toHaveLength(1);
|
|
||||||
|
expect(screen.getAllByRole('textbox')).toHaveLength(3);
|
||||||
|
expect(screen.getByText('Something')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invokes submit callback when submit event is triggered', () => {
|
it('invokes submit callback when submit event is triggered', async () => {
|
||||||
const form = wrapper.find('form');
|
setUp();
|
||||||
const preventDefault = jest.fn();
|
|
||||||
|
|
||||||
form.simulate('submit', { preventDefault });
|
expect(onSubmit).not.toHaveBeenCalled();
|
||||||
|
fireEvent.submit(screen.getByRole('form'), { preventDefault: jest.fn() });
|
||||||
expect(preventDefault).toHaveBeenCalled();
|
|
||||||
expect(onSubmit).toHaveBeenCalled();
|
expect(onSubmit).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue