shlink-web-client/test/servers/helpers/ServerForm.test.tsx
2022-03-07 16:27:25 +01:00

30 lines
932 B
TypeScript

import { shallow, ShallowWrapper } from 'enzyme';
import { ServerForm } from '../../../src/servers/helpers/ServerForm';
import { InputFormGroup } from '../../../src/utils/forms/InputFormGroup';
describe('<ServerForm />', () => {
let wrapper: ShallowWrapper;
const onSubmit = jest.fn();
beforeEach(() => {
wrapper = shallow(<ServerForm onSubmit={onSubmit}><span>Something</span></ServerForm>);
});
afterEach(() => wrapper?.unmount());
afterEach(jest.resetAllMocks);
it('renders components', () => {
expect(wrapper.find(InputFormGroup)).toHaveLength(3);
expect(wrapper.find('span')).toHaveLength(1);
});
it('invokes submit callback when submit event is triggered', () => {
const form = wrapper.find('form');
const preventDefault = jest.fn();
form.simulate('submit', { preventDefault });
expect(preventDefault).toHaveBeenCalled();
expect(onSubmit).toHaveBeenCalled();
});
});