Remove usages of vi.mock

This commit is contained in:
Alejandro Celaya
2023-12-18 23:38:34 +01:00
parent 598540aaac
commit f50d033551
6 changed files with 84 additions and 67 deletions

View File

@@ -1,14 +1,9 @@
import { render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { useParams } from 'react-router-dom';
import { ShlinkWebComponentContainerFactory } from '../../src/common/ShlinkWebComponentContainer';
import type { NonReachableServer, NotFoundServer, SelectedServer } from '../../src/servers/data';
import { checkAccessibility } from '../__helpers__/accessibility';
vi.mock('react-router-dom', async () => ({
...(await vi.importActual<any>('react-router-dom')),
useParams: vi.fn(),
}));
import { MemoryRouterWithParams } from '../__helpers__/MemoryRouterWithParams';
describe('<ShlinkWebComponentContainer />', () => {
const ShlinkWebComponentContainer = ShlinkWebComponentContainerFactory(fromPartial({
@@ -18,13 +13,11 @@ describe('<ShlinkWebComponentContainer />', () => {
ServerError: () => <>ServerError</>,
}));
const setUp = (selectedServer: SelectedServer) => render(
<ShlinkWebComponentContainer selectServer={vi.fn()} selectedServer={selectedServer} settings={{}} />,
<MemoryRouterWithParams params={{ serverId: 'abc123' }}>
<ShlinkWebComponentContainer selectServer={vi.fn()} selectedServer={selectedServer} settings={{}} />
</MemoryRouterWithParams>,
);
beforeEach(() => {
(useParams as any).mockReturnValue({ serverId: 'abc123' });
});
it('passes a11y checks', () => checkAccessibility(setUp(fromPartial({ version: '3.0.0' }))));
it('shows loading indicator while loading server', () => {