import { mount, ReactWrapper } from 'enzyme'; import { Mock } from 'ts-mockery'; import { History, Location } from 'history'; import { match } from 'react-router'; // eslint-disable-line @typescript-eslint/no-unused-vars import { EditServer as editServerConstruct } from '../../src/servers/EditServer'; import { ServerForm } from '../../src/servers/helpers/ServerForm'; import { ReachableServer } from '../../src/servers/data'; describe('', () => { let wrapper: ReactWrapper; const ServerError = jest.fn(); const editServerMock = jest.fn(); const goBack = jest.fn(); const historyMock = Mock.of({ goBack }); const match = Mock.of>({ params: { serverId: 'abc123' }, }); const selectedServer = Mock.of({ id: 'abc123', name: 'name', url: 'url', apiKey: 'apiKey', }); beforeEach(() => { const EditServer = editServerConstruct(ServerError); wrapper = mount( ()} selectedServer={selectedServer} selectServer={jest.fn()} />, ); }); afterEach(jest.resetAllMocks); afterEach(() => wrapper?.unmount()); it('renders components', () => { expect(wrapper.find(ServerForm)).toHaveLength(1); }); it('edits server and redirects to it when form is submitted', () => { const form = wrapper.find(ServerForm); form.simulate('submit', {}); expect(editServerMock).toHaveBeenCalledTimes(1); expect(goBack).toHaveBeenCalledTimes(1); }); });