mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-15 03:53:51 +00:00
Fixed most tests using react-router-dom hooks
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { identity } from 'ramda';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { History, Location } from 'history';
|
||||
import { match } from 'react-router'; // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import createShortUrlVisits, { ShortUrlVisitsProps } from '../../src/visits/ShortUrlVisits';
|
||||
import ShortUrlVisitsHeader from '../../src/visits/ShortUrlVisitsHeader';
|
||||
import { ShortUrlVisits as ShortUrlVisitsState } from '../../src/visits/reducers/shortUrlVisits';
|
||||
@@ -11,16 +9,16 @@ import VisitsStats from '../../src/visits/VisitsStats';
|
||||
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
||||
import { VisitsExporter } from '../../src/visits/services/VisitsExporter';
|
||||
|
||||
jest.mock('react-router-dom', () => ({
|
||||
...jest.requireActual('react-router-dom'),
|
||||
useNavigate: jest.fn().mockReturnValue(jest.fn()),
|
||||
useLocation: jest.fn().mockReturnValue({ search: '' }),
|
||||
useParams: jest.fn().mockReturnValue({ shortCode: 'abc123' }),
|
||||
}));
|
||||
|
||||
describe('<ShortUrlVisits />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
const getShortUrlVisitsMock = jest.fn();
|
||||
const match = Mock.of<match<{ shortCode: string }>>({
|
||||
params: { shortCode: 'abc123' },
|
||||
});
|
||||
const location = Mock.of<Location>({ search: '' });
|
||||
const history = Mock.of<History>({
|
||||
goBack: jest.fn(),
|
||||
});
|
||||
const ShortUrlVisits = createShortUrlVisits(Mock.all<VisitsExporter>());
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -30,9 +28,6 @@ describe('<ShortUrlVisits />', () => {
|
||||
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
|
||||
getShortUrlDetail={identity}
|
||||
getShortUrlVisits={getShortUrlVisitsMock}
|
||||
match={match}
|
||||
location={location}
|
||||
history={history}
|
||||
shortUrlVisits={Mock.of<ShortUrlVisitsState>({ loading: true, visits: [] })}
|
||||
shortUrlDetail={Mock.all<ShortUrlDetail>()}
|
||||
cancelGetShortUrlVisits={() => {}}
|
||||
@@ -40,8 +35,8 @@ describe('<ShortUrlVisits />', () => {
|
||||
).dive(); // Dive is needed as this component is wrapped in a HOC
|
||||
});
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
afterEach(() => wrapper.unmount());
|
||||
afterEach(jest.resetAllMocks);
|
||||
|
||||
it('renders visit stats and visits header', () => {
|
||||
const visitStats = wrapper.find(VisitsStats);
|
||||
|
||||
Reference in New Issue
Block a user