mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-14 19:43:49 +00:00
Update tests to use vi instead of jest
This commit is contained in:
@@ -9,12 +9,12 @@ import {
|
||||
|
||||
describe('shortUrlCreationReducer', () => {
|
||||
const shortUrl = fromPartial<ShortUrl>({});
|
||||
const createShortUrlCall = jest.fn();
|
||||
const createShortUrlCall = vi.fn();
|
||||
const buildShlinkApiClient = () => fromPartial<ShlinkApiClient>({ createShortUrl: createShortUrlCall });
|
||||
const createShortUrl = createShortUrlCreator(buildShlinkApiClient);
|
||||
const { reducer, resetCreateShortUrl } = shortUrlCreationReducerCreator(createShortUrl);
|
||||
|
||||
afterEach(jest.resetAllMocks);
|
||||
afterEach(vi.resetAllMocks);
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns loading on CREATE_SHORT_URL_START', () => {
|
||||
@@ -52,7 +52,7 @@ describe('shortUrlCreationReducer', () => {
|
||||
});
|
||||
|
||||
describe('createShortUrl', () => {
|
||||
const dispatch = jest.fn();
|
||||
const dispatch = vi.fn();
|
||||
const getState = () => fromPartial<ShlinkState>({});
|
||||
|
||||
it('calls API on success', async () => {
|
||||
|
||||
@@ -7,12 +7,12 @@ import {
|
||||
} from '../../../src/short-urls/reducers/shortUrlDeletion';
|
||||
|
||||
describe('shortUrlDeletionReducer', () => {
|
||||
const deleteShortUrlCall = jest.fn();
|
||||
const deleteShortUrlCall = vi.fn();
|
||||
const buildShlinkApiClient = () => fromPartial<ShlinkApiClient>({ deleteShortUrl: deleteShortUrlCall });
|
||||
const deleteShortUrl = deleteShortUrlCreator(buildShlinkApiClient);
|
||||
const { reducer, resetDeleteShortUrl } = shortUrlDeletionReducerCreator(deleteShortUrl);
|
||||
|
||||
beforeEach(jest.clearAllMocks);
|
||||
beforeEach(vi.clearAllMocks);
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns loading on DELETE_SHORT_URL_START', () =>
|
||||
@@ -56,8 +56,8 @@ describe('shortUrlDeletionReducer', () => {
|
||||
});
|
||||
|
||||
describe('deleteShortUrl', () => {
|
||||
const dispatch = jest.fn();
|
||||
const getState = jest.fn().mockReturnValue({ selectedServer: {} });
|
||||
const dispatch = vi.fn();
|
||||
const getState = vi.fn().mockReturnValue({ selectedServer: {} });
|
||||
|
||||
it.each(
|
||||
[[undefined], [null], ['example.com']],
|
||||
|
||||
@@ -6,11 +6,11 @@ import { shortUrlDetailReducerCreator } from '../../../src/short-urls/reducers/s
|
||||
import type { ShortUrlsList } from '../../../src/short-urls/reducers/shortUrlsList';
|
||||
|
||||
describe('shortUrlDetailReducer', () => {
|
||||
const getShortUrlCall = jest.fn();
|
||||
const getShortUrlCall = vi.fn();
|
||||
const buildShlinkApiClient = () => fromPartial<ShlinkApiClient>({ getShortUrl: getShortUrlCall });
|
||||
const { reducer, getShortUrlDetail } = shortUrlDetailReducerCreator(buildShlinkApiClient);
|
||||
|
||||
beforeEach(jest.clearAllMocks);
|
||||
beforeEach(vi.clearAllMocks);
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns loading on GET_SHORT_URL_DETAIL_START', () => {
|
||||
@@ -41,7 +41,7 @@ describe('shortUrlDetailReducer', () => {
|
||||
});
|
||||
|
||||
describe('getShortUrlDetail', () => {
|
||||
const dispatchMock = jest.fn();
|
||||
const dispatchMock = vi.fn();
|
||||
const buildGetState = (shortUrlsList?: ShortUrlsList) => () => fromPartial<ShlinkState>({ shortUrlsList });
|
||||
|
||||
it.each([
|
||||
|
||||
@@ -11,12 +11,12 @@ describe('shortUrlEditionReducer', () => {
|
||||
const longUrl = 'https://shlink.io';
|
||||
const shortCode = 'abc123';
|
||||
const shortUrl = fromPartial<ShortUrl>({ longUrl, shortCode });
|
||||
const updateShortUrl = jest.fn().mockResolvedValue(shortUrl);
|
||||
const buildShlinkApiClient = jest.fn().mockReturnValue({ updateShortUrl });
|
||||
const updateShortUrl = vi.fn().mockResolvedValue(shortUrl);
|
||||
const buildShlinkApiClient = vi.fn().mockReturnValue({ updateShortUrl });
|
||||
const editShortUrl = editShortUrlCreator(buildShlinkApiClient);
|
||||
const { reducer } = shortUrlEditionReducerCreator(editShortUrl);
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
afterEach(vi.clearAllMocks);
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns loading on EDIT_SHORT_URL_START', () => {
|
||||
@@ -46,12 +46,12 @@ describe('shortUrlEditionReducer', () => {
|
||||
});
|
||||
|
||||
describe('editShortUrl', () => {
|
||||
const dispatch = jest.fn();
|
||||
const dispatch = vi.fn();
|
||||
const createGetState = (selectedServer: SelectedServer = null) => () => fromPartial<ShlinkState>({
|
||||
selectedServer,
|
||||
});
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
afterEach(vi.clearAllMocks);
|
||||
|
||||
it.each([[undefined], [null], ['example.com']])('dispatches short URL on success', async (domain) => {
|
||||
await editShortUrl({ shortCode, domain, data: { longUrl } })(dispatch, createGetState(), {});
|
||||
|
||||
@@ -14,14 +14,14 @@ import type { CreateVisit } from '../../../src/visits/types';
|
||||
|
||||
describe('shortUrlsListReducer', () => {
|
||||
const shortCode = 'abc123';
|
||||
const listShortUrlsMock = jest.fn();
|
||||
const listShortUrlsMock = vi.fn();
|
||||
const buildShlinkApiClient = () => fromPartial<ShlinkApiClient>({ listShortUrls: listShortUrlsMock });
|
||||
const listShortUrls = listShortUrlsCreator(buildShlinkApiClient);
|
||||
const editShortUrl = editShortUrlCreator(buildShlinkApiClient);
|
||||
const createShortUrl = createShortUrlCreator(buildShlinkApiClient);
|
||||
const { reducer } = shortUrlsListReducerCreator(listShortUrls, editShortUrl, createShortUrl);
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
afterEach(vi.clearAllMocks);
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns loading on LIST_SHORT_URLS_START', () =>
|
||||
@@ -188,8 +188,8 @@ describe('shortUrlsListReducer', () => {
|
||||
});
|
||||
|
||||
describe('listShortUrls', () => {
|
||||
const dispatch = jest.fn();
|
||||
const getState = jest.fn().mockReturnValue({ selectedServer: {} });
|
||||
const dispatch = vi.fn();
|
||||
const getState = vi.fn().mockReturnValue({ selectedServer: {} });
|
||||
|
||||
it('dispatches proper actions if API client request succeeds', async () => {
|
||||
listShortUrlsMock.mockResolvedValue({});
|
||||
|
||||
Reference in New Issue
Block a user