diff --git a/test/__mocks__/Window.mock.ts b/test/__mocks__/Window.mock.ts index dbd91da6..8b718753 100644 --- a/test/__mocks__/Window.mock.ts +++ b/test/__mocks__/Window.mock.ts @@ -1,18 +1,18 @@ import { fromAny, fromPartial } from '@total-typescript/shoehorn'; const createLinkMock = () => ({ - setAttribute: jest.fn(), - click: jest.fn(), + setAttribute: vi.fn(), + click: vi.fn(), style: {}, }); -export const appendChild = jest.fn(); +export const appendChild = vi.fn(); -export const removeChild = jest.fn(); +export const removeChild = vi.fn(); export const windowMock = fromPartial({ document: fromAny({ - createElement: jest.fn(createLinkMock), + createElement: vi.fn(createLinkMock), body: { appendChild, removeChild }, }), }); diff --git a/test/api/services/ShlinkApiClient.test.ts b/test/api/services/ShlinkApiClient.test.ts index 8423e68d..3cd1d781 100644 --- a/test/api/services/ShlinkApiClient.test.ts +++ b/test/api/services/ShlinkApiClient.test.ts @@ -7,8 +7,8 @@ import type { ShortUrl, ShortUrlsOrder } from '../../../src/short-urls/data'; import type { OptionalString } from '../../../src/utils/utils'; describe('ShlinkApiClient', () => { - const fetchJson = jest.fn().mockResolvedValue({}); - const fetchEmpty = jest.fn().mockResolvedValue(undefined); + const fetchJson = vi.fn().mockResolvedValue({}); + const fetchEmpty = vi.fn().mockResolvedValue(undefined); const httpClient = fromPartial({ fetchJson, fetchEmpty }); const buildApiClient = () => new ShlinkApiClient(httpClient, '', ''); const shortCodesWithDomainCombinations: [string, OptionalString][] = [ @@ -17,7 +17,7 @@ describe('ShlinkApiClient', () => { ['abc123', 'example.com'], ]; - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); describe('listShortUrls', () => { const expectedList = ['foo', 'bar']; diff --git a/test/app/App.test.tsx b/test/app/App.test.tsx index 6063b05a..ca1b9bdb 100644 --- a/test/app/App.test.tsx +++ b/test/app/App.test.tsx @@ -32,7 +32,7 @@ describe('', () => { ); }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders children components', () => { setUp(); diff --git a/test/common/AppUpdateBanner.test.tsx b/test/common/AppUpdateBanner.test.tsx index 4dfcd207..83ded1e2 100644 --- a/test/common/AppUpdateBanner.test.tsx +++ b/test/common/AppUpdateBanner.test.tsx @@ -3,11 +3,11 @@ import { AppUpdateBanner } from '../../src/common/AppUpdateBanner'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const toggle = jest.fn(); - const forceUpdate = jest.fn(); + const toggle = vi.fn(); + const forceUpdate = vi.fn(); const setUp = () => renderWithEvents(); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders initial state', () => { setUp(); diff --git a/test/common/AsideMenu.test.tsx b/test/common/AsideMenu.test.tsx index c0fa448a..9a4f7d25 100644 --- a/test/common/AsideMenu.test.tsx +++ b/test/common/AsideMenu.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '@testing-library/react'; import { fromPartial } from '@total-typescript/shoehorn'; -import { MemoryRouter } from 'react-router-dom'; +import { MemoryRouter } from 'react-router'; import { AsideMenu as createAsideMenu } from '../../src/common/AsideMenu'; describe('', () => { diff --git a/test/common/ErrorHandler.test.tsx b/test/common/ErrorHandler.test.tsx index 41c82dde..5fd40c21 100644 --- a/test/common/ErrorHandler.test.tsx +++ b/test/common/ErrorHandler.test.tsx @@ -8,17 +8,17 @@ const ComponentWithError = () => { }; describe('', () => { - const reload = jest.fn(); + const reload = vi.fn(); const window = fromPartial({ location: { reload }, }); - const cons = fromPartial({ error: jest.fn() }); + const cons = fromPartial({ error: vi.fn() }); const ErrorHandler = createErrorHandler(window, cons); beforeEach(() => { - jest.spyOn(console, 'error').mockImplementation(() => {}); // Silence react errors + vi.spyOn(console, 'error').mockImplementation(() => {}); // Silence react errors }); - afterEach(jest.resetAllMocks); + afterEach(vi.resetAllMocks); it('renders children when no error has occurred', () => { render(Foo} />); diff --git a/test/common/Home.test.tsx b/test/common/Home.test.tsx index 8e619b89..92a7e1d2 100644 --- a/test/common/Home.test.tsx +++ b/test/common/Home.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '@testing-library/react'; import { fromPartial } from '@total-typescript/shoehorn'; -import { MemoryRouter } from 'react-router-dom'; +import { MemoryRouter } from 'react-router'; import { Home } from '../../src/common/Home'; import type { ServersMap, ServerWithId } from '../../src/servers/data'; diff --git a/test/common/MenuLayout.test.tsx b/test/common/MenuLayout.test.tsx index a6ae0191..02e64c6c 100644 --- a/test/common/MenuLayout.test.tsx +++ b/test/common/MenuLayout.test.tsx @@ -6,7 +6,7 @@ import { MenuLayout as createMenuLayout } from '../../src/common/MenuLayout'; import type { NonReachableServer, NotFoundServer, SelectedServer } from '../../src/servers/data'; import type { SemVer } from '../../src/utils/helpers/version'; -jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useParams: jest.fn() })); +vi.mock('react-router-dom', async () => ({ ...(await vi.importActual('react-router-dom')), useParams: vi.fn() })); describe('', () => { const MenuLayout = createMenuLayout( @@ -31,9 +31,9 @@ describe('', () => { return render( , @@ -44,7 +44,7 @@ describe('', () => { (useParams as any).mockReturnValue({ serverId: 'abc123' }); }); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('shows loading indicator while loading server', () => { setUp(null); diff --git a/test/common/NotFound.test.tsx b/test/common/NotFound.test.tsx index f923a375..ce5f7dc6 100644 --- a/test/common/NotFound.test.tsx +++ b/test/common/NotFound.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '@testing-library/react'; -import { MemoryRouter } from 'react-router-dom'; +import { MemoryRouter } from 'react-router'; import { NotFound } from '../../src/common/NotFound'; describe('', () => { diff --git a/test/common/ScrollToTop.test.tsx b/test/common/ScrollToTop.test.tsx index f95907fc..e1d75933 100644 --- a/test/common/ScrollToTop.test.tsx +++ b/test/common/ScrollToTop.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '@testing-library/react'; -import { MemoryRouter } from 'react-router-dom'; +import { MemoryRouter } from 'react-router'; import { ScrollToTop } from '../../src/common/ScrollToTop'; describe('', () => { diff --git a/test/common/SimplePaginator.test.tsx b/test/common/SimplePaginator.test.tsx index 7b2c060a..f0b9e1ae 100644 --- a/test/common/SimplePaginator.test.tsx +++ b/test/common/SimplePaginator.test.tsx @@ -4,7 +4,7 @@ import { ELLIPSIS } from '../../src/utils/helpers/pagination'; describe('', () => { const setUp = (pagesCount: number, currentPage = 1) => render( - , + , ); it.each([-3, -2, 0, 1])('renders empty when the amount of pages is smaller than 2', (pagesCount) => { diff --git a/test/common/services/HttpClient.test.ts b/test/common/services/HttpClient.test.ts index ea01faf5..43b13ac4 100644 --- a/test/common/services/HttpClient.test.ts +++ b/test/common/services/HttpClient.test.ts @@ -1,10 +1,10 @@ import { HttpClient } from '../../../src/common/services/HttpClient'; describe('HttpClient', () => { - const fetch = jest.fn(); + const fetch = vi.fn(); const httpClient = new HttpClient(fetch); - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); describe('fetchJson', () => { it('throws json on success', async () => { diff --git a/test/common/services/ImageDownloader.test.ts b/test/common/services/ImageDownloader.test.ts index d7c80dc7..304a54e9 100644 --- a/test/common/services/ImageDownloader.test.ts +++ b/test/common/services/ImageDownloader.test.ts @@ -4,12 +4,12 @@ import { ImageDownloader } from '../../../src/common/services/ImageDownloader'; import { windowMock } from '../../__mocks__/Window.mock'; describe('ImageDownloader', () => { - const fetchBlob = jest.fn(); + const fetchBlob = vi.fn(); const httpClient = fromPartial({ fetchBlob }); let imageDownloader: ImageDownloader; beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); (global as any).URL = { createObjectURL: () => '' }; imageDownloader = new ImageDownloader(httpClient, windowMock); diff --git a/test/common/services/ReportExporter.test.ts b/test/common/services/ReportExporter.test.ts index 8fdc9cce..5dfa9cc8 100644 --- a/test/common/services/ReportExporter.test.ts +++ b/test/common/services/ReportExporter.test.ts @@ -4,10 +4,10 @@ import type { NormalizedVisit } from '../../../src/visits/types'; import { windowMock } from '../../__mocks__/Window.mock'; describe('ReportExporter', () => { - const jsonToCsv = jest.fn(); + const jsonToCsv = vi.fn(); let exporter: ReportExporter; - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); beforeEach(() => { (global as any).Blob = class Blob {}; (global as any).URL = { createObjectURL: () => '' }; diff --git a/test/domains/DomainRow.test.tsx b/test/domains/DomainRow.test.tsx index a6d2969a..f3d6bc3e 100644 --- a/test/domains/DomainRow.test.tsx +++ b/test/domains/DomainRow.test.tsx @@ -22,8 +22,8 @@ describe('', () => { domain={domain} defaultRedirects={defaultRedirects} selectedServer={fromPartial({})} - editDomainRedirects={jest.fn()} - checkDomainHealth={jest.fn()} + editDomainRedirects={vi.fn()} + checkDomainHealth={vi.fn()} /> , diff --git a/test/domains/DomainSelector.test.tsx b/test/domains/DomainSelector.test.tsx index 008414af..d7e055cf 100644 --- a/test/domains/DomainSelector.test.tsx +++ b/test/domains/DomainSelector.test.tsx @@ -13,10 +13,10 @@ describe('', () => { ], }); const setUp = (value = '') => renderWithEvents( - , + , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it.each([ ['', 'Domain', 'domains-dropdown__toggle-btn'], diff --git a/test/domains/ManageDomains.test.tsx b/test/domains/ManageDomains.test.tsx index 30cf6048..fada56ae 100644 --- a/test/domains/ManageDomains.test.tsx +++ b/test/domains/ManageDomains.test.tsx @@ -7,20 +7,20 @@ import type { DomainsList } from '../../src/domains/reducers/domainsList'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const listDomains = jest.fn(); - const filterDomains = jest.fn(); + const listDomains = vi.fn(); + const filterDomains = vi.fn(); const setUp = (domainsList: DomainsList) => renderWithEvents( , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('shows loading message while domains are loading', () => { setUp(fromPartial({ loading: true, filteredDomains: [] })); diff --git a/test/domains/helpers/DomainDropdown.test.tsx b/test/domains/helpers/DomainDropdown.test.tsx index f121978b..a5c2ecd3 100644 --- a/test/domains/helpers/DomainDropdown.test.tsx +++ b/test/domains/helpers/DomainDropdown.test.tsx @@ -8,7 +8,7 @@ import type { SemVer } from '../../../src/utils/helpers/version'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const editDomainRedirects = jest.fn().mockResolvedValue(undefined); + const editDomainRedirects = vi.fn().mockResolvedValue(undefined); const setUp = (domain?: Domain, selectedServer?: SelectedServer) => renderWithEvents( ', () => { , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders expected menu items', () => { setUp(); diff --git a/test/domains/helpers/DomainStatusIcon.test.tsx b/test/domains/helpers/DomainStatusIcon.test.tsx index d695a92b..b1ee76bd 100644 --- a/test/domains/helpers/DomainStatusIcon.test.tsx +++ b/test/domains/helpers/DomainStatusIcon.test.tsx @@ -5,12 +5,12 @@ import { DomainStatusIcon } from '../../../src/domains/helpers/DomainStatusIcon' import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const matchMedia = jest.fn().mockReturnValue(fromPartial({ matches: false })); + const matchMedia = vi.fn().mockReturnValue(fromPartial({ matches: false })); const setUp = (status: DomainStatus) => renderWithEvents( , ); - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); it.each([ ['validating' as DomainStatus], diff --git a/test/domains/helpers/EditDomainRedirectsModal.test.tsx b/test/domains/helpers/EditDomainRedirectsModal.test.tsx index dad4e887..becf839b 100644 --- a/test/domains/helpers/EditDomainRedirectsModal.test.tsx +++ b/test/domains/helpers/EditDomainRedirectsModal.test.tsx @@ -5,8 +5,8 @@ import { EditDomainRedirectsModal } from '../../../src/domains/helpers/EditDomai import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const editDomainRedirects = jest.fn().mockResolvedValue(undefined); - const toggle = jest.fn(); + const editDomainRedirects = vi.fn().mockResolvedValue(undefined); + const toggle = vi.fn(); const domain = fromPartial({ domain: 'foo.com', redirects: { @@ -17,7 +17,7 @@ describe('', () => { , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders domain in header', () => { setUp(); diff --git a/test/domains/helpers/__snapshots__/DomainStatusIcon.test.tsx.snap b/test/domains/helpers/__snapshots__/DomainStatusIcon.test.tsx.snap index 7513f536..3ccd8237 100644 --- a/test/domains/helpers/__snapshots__/DomainStatusIcon.test.tsx.snap +++ b/test/domains/helpers/__snapshots__/DomainStatusIcon.test.tsx.snap @@ -1,4 +1,92 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders expected icon and tooltip when status is not validating 1`] = ` + +`; + +exports[` > renders expected icon and tooltip when status is not validating 2`] = ` + + + +`; + +exports[` > renders expected icon and tooltip when status is not validating 3`] = ` + + + +`; + +exports[` > renders proper tooltip based on state 1`] = ` + +`; + +exports[` > renders proper tooltip based on state 2`] = ` + +`; exports[` renders expected icon and tooltip when status is not validating 1`] = ` { - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); describe('editDomainRedirects', () => { const domain = 'example.com'; const redirects = fromPartial({}); - const dispatch = jest.fn(); - const getState = jest.fn(); - const editDomainRedirectsCall = jest.fn(); + const dispatch = vi.fn(); + const getState = vi.fn(); + const editDomainRedirectsCall = vi.fn(); const buildShlinkApiClient = () => fromPartial({ editDomainRedirects: editDomainRedirectsCall }); const editDomainRedirectsAction = editDomainRedirects(buildShlinkApiClient); diff --git a/test/domains/reducers/domainsList.test.ts b/test/domains/reducers/domainsList.test.ts index 9381e671..afadeca8 100644 --- a/test/domains/reducers/domainsList.test.ts +++ b/test/domains/reducers/domainsList.test.ts @@ -13,10 +13,10 @@ import { } from '../../../src/domains/reducers/domainsList'; describe('domainsListReducer', () => { - const dispatch = jest.fn(); - const getState = jest.fn(); - const listDomains = jest.fn(); - const health = jest.fn(); + const dispatch = vi.fn(); + const getState = vi.fn(); + const listDomains = vi.fn(); + const health = vi.fn(); const buildShlinkApiClient = () => fromPartial({ listDomains, health }); const filteredDomains: Domain[] = [ fromPartial({ domain: 'foo', status: 'validating' }), @@ -30,7 +30,7 @@ describe('domainsListReducer', () => { editDomainRedirectsThunk, ); - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); describe('reducer', () => { it('returns loading on LIST_DOMAINS_START', () => { diff --git a/test/mercure/helpers/index.test.tsx b/test/mercure/helpers/index.test.tsx index 15a76d15..12fee3d2 100644 --- a/test/mercure/helpers/index.test.tsx +++ b/test/mercure/helpers/index.test.tsx @@ -4,14 +4,14 @@ import { identity } from 'ramda'; import { bindToMercureTopic } from '../../../src/mercure/helpers'; import type { MercureInfo } from '../../../src/mercure/reducers/mercureInfo'; -jest.mock('event-source-polyfill'); +vi.mock('event-source-polyfill'); describe('helpers', () => { - afterEach(jest.resetAllMocks); + afterEach(vi.resetAllMocks); describe('bindToMercureTopic', () => { - const onMessage = jest.fn(); - const onTokenExpired = jest.fn(); + const onMessage = vi.fn(); + const onTokenExpired = vi.fn(); it.each([ [fromPartial({ loading: true, error: false, mercureHubUrl: 'foo' })], diff --git a/test/mercure/reducers/mercureInfo.test.ts b/test/mercure/reducers/mercureInfo.test.ts index 907a7b67..1079f7d1 100644 --- a/test/mercure/reducers/mercureInfo.test.ts +++ b/test/mercure/reducers/mercureInfo.test.ts @@ -8,11 +8,11 @@ describe('mercureInfoReducer', () => { mercureHubUrl: 'http://example.com/.well-known/mercure', token: 'abc.123.def', }; - const getMercureInfo = jest.fn(); + const getMercureInfo = vi.fn(); const buildShlinkApiClient = () => fromPartial({ mercureInfo: getMercureInfo }); const { loadMercureInfo, reducer } = mercureInfoReducerCreator(buildShlinkApiClient); - beforeEach(jest.resetAllMocks); + beforeEach(vi.resetAllMocks); describe('reducer', () => { it('returns loading on GET_MERCURE_INFO_START', () => { @@ -37,8 +37,8 @@ describe('mercureInfoReducer', () => { }); describe('loadMercureInfo', () => { - const dispatch = jest.fn(); - const createGetStateMock = (enabled: boolean): GetState => jest.fn().mockReturnValue({ + const dispatch = vi.fn(); + const createGetStateMock = (enabled: boolean): GetState => vi.fn().mockReturnValue({ settings: { realTimeUpdates: { enabled }, }, diff --git a/test/servers/CreateServer.test.tsx b/test/servers/CreateServer.test.tsx index adbc1b2c..0af5591f 100644 --- a/test/servers/CreateServer.test.tsx +++ b/test/servers/CreateServer.test.tsx @@ -5,17 +5,20 @@ import { CreateServer as createCreateServer } from '../../src/servers/CreateServ import type { ServerWithId } from '../../src/servers/data'; import { renderWithEvents } from '../__helpers__/setUpTest'; -jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() })); +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useNavigate: vi.fn(), +})); describe('', () => { - const createServersMock = jest.fn(); - const navigate = jest.fn(); + const createServersMock = vi.fn(); + const navigate = vi.fn(); const servers = { foo: fromPartial({ url: 'https://existing_url.com', apiKey: 'existing_api_key' }) }; const setUp = (serversImported = false, importFailed = false) => { (useNavigate as any).mockReturnValue(navigate); let callCount = 0; - const useTimeoutToggle = jest.fn().mockImplementation(() => { + const useTimeoutToggle = vi.fn().mockImplementation(() => { const result = [callCount % 2 === 0 ? serversImported : importFailed, () => null]; callCount += 1; return result; @@ -25,7 +28,7 @@ describe('', () => { return renderWithEvents(); }; - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); it('shows success message when imported is true', () => { setUp(true); diff --git a/test/servers/DeleteServerModal.test.tsx b/test/servers/DeleteServerModal.test.tsx index f2f66d42..ab2bf43d 100644 --- a/test/servers/DeleteServerModal.test.tsx +++ b/test/servers/DeleteServerModal.test.tsx @@ -5,11 +5,14 @@ import { DeleteServerModal } from '../../src/servers/DeleteServerModal'; import { renderWithEvents } from '../__helpers__/setUpTest'; import { TestModalWrapper } from '../__helpers__/TestModalWrapper'; -jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() })); +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useNavigate: vi.fn(), +})); describe('', () => { - const deleteServerMock = jest.fn(); - const navigate = jest.fn(); + const deleteServerMock = vi.fn(); + const navigate = vi.fn(); const serverName = 'the_server_name'; const setUp = () => { (useNavigate as any).mockReturnValue(navigate); @@ -27,7 +30,7 @@ describe('', () => { ); }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders a modal window', () => { setUp(); diff --git a/test/servers/EditServer.test.tsx b/test/servers/EditServer.test.tsx index 4d680158..17d5b3ad 100644 --- a/test/servers/EditServer.test.tsx +++ b/test/servers/EditServer.test.tsx @@ -5,12 +5,15 @@ import type { ReachableServer, SelectedServer } from '../../src/servers/data'; import { EditServer as editServerConstruct } from '../../src/servers/EditServer'; import { renderWithEvents } from '../__helpers__/setUpTest'; -jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() })); +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useNavigate: vi.fn(), +})); describe('', () => { - const ServerError = jest.fn(); - const editServerMock = jest.fn(); - const navigate = jest.fn(); + const ServerError = vi.fn(); + const editServerMock = vi.fn(); + const navigate = vi.fn(); const defaultSelectedServer = fromPartial({ id: 'abc123', name: 'the_name', @@ -20,7 +23,7 @@ describe('', () => { const EditServer = editServerConstruct(ServerError); const setUp = (selectedServer: SelectedServer = defaultSelectedServer) => renderWithEvents( - + , ); @@ -28,7 +31,7 @@ describe('', () => { (useNavigate as any).mockReturnValue(navigate); }); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders nothing if selected server is not reachable', () => { setUp(fromPartial({})); diff --git a/test/servers/ManageServers.test.tsx b/test/servers/ManageServers.test.tsx index ce5c2a08..3e61c34a 100644 --- a/test/servers/ManageServers.test.tsx +++ b/test/servers/ManageServers.test.tsx @@ -7,9 +7,9 @@ import type { ServersExporter } from '../../src/servers/services/ServersExporter import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const exportServers = jest.fn(); + const exportServers = vi.fn(); const serversExporter = fromPartial({ exportServers }); - const useTimeoutToggle = jest.fn().mockReturnValue([false, jest.fn()]); + const useTimeoutToggle = vi.fn().mockReturnValue([false, vi.fn()]); const ManageServers = createManageServers( serversExporter, () => ImportServersBtn, @@ -23,7 +23,7 @@ describe('', () => { , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('shows search field which allows searching servers, affecting te amount of rendered rows', async () => { const { user } = setUp({ @@ -85,7 +85,7 @@ describe('', () => { }); it.each([[true], [false]])('shows an error message if an error occurs while importing servers', (hasError) => { - useTimeoutToggle.mockReturnValue([hasError, jest.fn()]); + useTimeoutToggle.mockReturnValue([hasError, vi.fn()]); setUp({ foo: createServerMock('foo') }); diff --git a/test/servers/ManageServersRowDropdown.test.tsx b/test/servers/ManageServersRowDropdown.test.tsx index 9d1d536b..53064f81 100644 --- a/test/servers/ManageServersRowDropdown.test.tsx +++ b/test/servers/ManageServersRowDropdown.test.tsx @@ -9,7 +9,7 @@ describe('', () => { const ManageServersRowDropdown = createManageServersRowDropdown( ({ isOpen }) => DeleteServerModal {isOpen ? '[OPEN]' : '[CLOSED]'}, ); - const setAutoConnect = jest.fn(); + const setAutoConnect = vi.fn(); const setUp = (autoConnect = false) => { const server = fromPartial({ id: 'abc123', autoConnect }); return renderWithEvents( @@ -19,7 +19,7 @@ describe('', () => { ); }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders expected amount of dropdown items', async () => { const { user } = setUp(); diff --git a/test/servers/Overview.test.tsx b/test/servers/Overview.test.tsx index bff2b42d..9a8002eb 100644 --- a/test/servers/Overview.test.tsx +++ b/test/servers/Overview.test.tsx @@ -9,9 +9,9 @@ import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const ShortUrlsTable = () => <>ShortUrlsTable; const CreateShortUrl = () => <>CreateShortUrl; - const listShortUrls = jest.fn(); - const listTags = jest.fn(); - const loadVisitsOverview = jest.fn(); + const listShortUrls = vi.fn(); + const listTags = vi.fn(); + const loadVisitsOverview = vi.fn(); const Overview = overviewCreator(ShortUrlsTable, CreateShortUrl); const shortUrls = { pagination: { totalItems: 83710 }, @@ -31,8 +31,8 @@ describe('', () => { orphanVisits: { total: 28, bots: 15, nonBots: 13 }, })} selectedServer={fromPartial({ id: serverId })} - createNewVisits={jest.fn()} - loadMercureInfo={jest.fn()} + createNewVisits={vi.fn()} + loadMercureInfo={vi.fn()} mercureInfo={fromPartial({})} settings={fromPartial({ visits: { excludeBots } })} /> diff --git a/test/servers/__snapshots__/DeleteServerButton.test.tsx.snap b/test/servers/__snapshots__/DeleteServerButton.test.tsx.snap index f47cfe0e..d332a540 100644 --- a/test/servers/__snapshots__/DeleteServerButton.test.tsx.snap +++ b/test/servers/__snapshots__/DeleteServerButton.test.tsx.snap @@ -1,4 +1,59 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders expected content 1`] = ` + + + Foo bar + + +`; + +exports[` > renders expected content 2`] = ` + + + baz + + +`; + +exports[` > renders expected content 3`] = ` + + + something + + +`; + +exports[` > renders expected content 4`] = ` + + + + Remove this server + + +`; exports[` renders expected content 1`] = ` diff --git a/test/servers/__snapshots__/ManageServersRow.test.tsx.snap b/test/servers/__snapshots__/ManageServersRow.test.tsx.snap index 9ebc2a4c..b777a57b 100644 --- a/test/servers/__snapshots__/ManageServersRow.test.tsx.snap +++ b/test/servers/__snapshots__/ManageServersRow.test.tsx.snap @@ -1,4 +1,101 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders auto-connect icon only if server is autoConnect 1`] = ` +
+ + + + + + + + + +
+ + + + My server + + + https://example.com + + + ManageServersRowDropdown + +
+
+`; + +exports[` > renders auto-connect icon only if server is autoConnect 2`] = ` +
+ + + + + + + + +
+ + + My server + + + https://example.com + + + ManageServersRowDropdown + +
+
+`; exports[` renders auto-connect icon only if server is autoConnect 1`] = `
diff --git a/test/servers/helpers/DuplicatedServersModal.test.tsx b/test/servers/helpers/DuplicatedServersModal.test.tsx index b4918fc4..8d88b844 100644 --- a/test/servers/helpers/DuplicatedServersModal.test.tsx +++ b/test/servers/helpers/DuplicatedServersModal.test.tsx @@ -5,14 +5,14 @@ import { DuplicatedServersModal } from '../../../src/servers/helpers/DuplicatedS import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const onDiscard = jest.fn(); - const onSave = jest.fn(); + const onDiscard = vi.fn(); + const onSave = vi.fn(); const setUp = (duplicatedServers: ServerData[] = []) => renderWithEvents( , ); const mockServer = (data: Partial = {}) => fromPartial(data); - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); it.each([ [[], 0], diff --git a/test/servers/helpers/ImportServersBtn.test.tsx b/test/servers/helpers/ImportServersBtn.test.tsx index a452e094..69f004ad 100644 --- a/test/servers/helpers/ImportServersBtn.test.tsx +++ b/test/servers/helpers/ImportServersBtn.test.tsx @@ -10,9 +10,9 @@ import type { ServersImporter } from '../../../src/servers/services/ServersImpor import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const onImportMock = jest.fn(); - const createServersMock = jest.fn(); - const importServersFromFile = jest.fn().mockResolvedValue([]); + const onImportMock = vi.fn(); + const createServersMock = vi.fn(); + const importServersFromFile = vi.fn().mockResolvedValue([]); const serversImporterMock = fromPartial({ importServersFromFile }); const ImportServersBtn = createImportServersBtn(serversImporterMock); const setUp = (props: Partial = {}, servers: ServersMap = {}) => renderWithEvents( @@ -24,7 +24,7 @@ describe('', () => { />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('shows tooltip on button hover', async () => { const { user } = setUp(); diff --git a/test/servers/helpers/ServerForm.test.tsx b/test/servers/helpers/ServerForm.test.tsx index ad8c543c..088417f5 100644 --- a/test/servers/helpers/ServerForm.test.tsx +++ b/test/servers/helpers/ServerForm.test.tsx @@ -2,10 +2,10 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { ServerForm } from '../../../src/servers/helpers/ServerForm'; describe('', () => { - const onSubmit = jest.fn(); + const onSubmit = vi.fn(); const setUp = () => render(Something); - afterEach(jest.resetAllMocks); + afterEach(vi.resetAllMocks); it('renders components', () => { setUp(); @@ -18,7 +18,7 @@ describe('', () => { setUp(); expect(onSubmit).not.toHaveBeenCalled(); - fireEvent.submit(screen.getByRole('form'), { preventDefault: jest.fn() }); + fireEvent.submit(screen.getByRole('form'), { preventDefault: vi.fn() }); expect(onSubmit).toHaveBeenCalled(); }); }); diff --git a/test/servers/reducers/remoteServers.test.ts b/test/servers/reducers/remoteServers.test.ts index 230488c6..fef79208 100644 --- a/test/servers/reducers/remoteServers.test.ts +++ b/test/servers/reducers/remoteServers.test.ts @@ -3,11 +3,11 @@ import type { HttpClient } from '../../../src/common/services/HttpClient'; import { fetchServers } from '../../../src/servers/reducers/remoteServers'; describe('remoteServersReducer', () => { - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); describe('fetchServers', () => { - const dispatch = jest.fn(); - const fetchJson = jest.fn(); + const dispatch = vi.fn(); + const fetchJson = vi.fn(); const httpClient = fromPartial({ fetchJson }); it.each([ @@ -81,7 +81,7 @@ describe('remoteServersReducer', () => { fetchJson.mockResolvedValue(mockedValue); const doFetchServers = fetchServers(httpClient); - await doFetchServers()(dispatch, jest.fn(), {}); + await doFetchServers()(dispatch, vi.fn(), {}); expect(dispatch).toHaveBeenCalledTimes(3); expect(dispatch).toHaveBeenNthCalledWith(2, expect.objectContaining({ payload: expectedNewServers })); diff --git a/test/servers/reducers/selectedServer.test.ts b/test/servers/reducers/selectedServer.test.ts index 34609864..b1818347 100644 --- a/test/servers/reducers/selectedServer.test.ts +++ b/test/servers/reducers/selectedServer.test.ts @@ -13,13 +13,13 @@ import { } from '../../../src/servers/reducers/selectedServer'; describe('selectedServerReducer', () => { - const dispatch = jest.fn(); - const health = jest.fn(); - const buildApiClient = jest.fn().mockReturnValue(fromPartial({ health })); + const dispatch = vi.fn(); + const health = vi.fn(); + const buildApiClient = vi.fn().mockReturnValue(fromPartial({ health })); const selectServer = selectServerCreator(buildApiClient); const { reducer } = selectedServerReducerCreator(selectServer); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); describe('reducer', () => { it('returns default when action is RESET_SELECTED_SERVER', () => @@ -33,7 +33,7 @@ describe('selectedServerReducer', () => { describe('selectServer', () => { const version = '1.19.0'; - const createGetStateMock = (id: string) => jest.fn().mockReturnValue({ + const createGetStateMock = (id: string) => vi.fn().mockReturnValue({ servers: { [id]: { id }, }, @@ -77,7 +77,7 @@ describe('selectedServerReducer', () => { it('dispatches error when server is not found', async () => { const id = uuid(); - const getState = jest.fn(() => fromPartial({ servers: {} })); + const getState = vi.fn(() => fromPartial({ servers: {} })); const expectedSelectedServer: NotFoundServer = { serverNotFound: true }; await selectServer(id)(dispatch, getState, {}); @@ -89,8 +89,8 @@ describe('selectedServerReducer', () => { }); describe('selectServerListener', () => { - const getState = jest.fn(() => ({})); - const loadMercureInfo = jest.fn(); + const getState = vi.fn(() => ({})); + const loadMercureInfo = vi.fn(); const { middleware } = selectServerListener(selectServer, loadMercureInfo); it.each([ @@ -98,7 +98,7 @@ describe('selectedServerReducer', () => { [fromPartial({ serverNotFound: true }), 0], [fromPartial({ serverNotReachable: true }), 0], ])('dispatches loadMercureInfo when provided server is reachable', (payload, expectedCalls) => { - middleware({ dispatch, getState })(jest.fn())({ + middleware({ dispatch, getState })(vi.fn())({ payload, type: selectServer.fulfilled.toString(), }); @@ -108,7 +108,7 @@ describe('selectedServerReducer', () => { }); it('does not dispatch loadMercureInfo when action is not of the proper type', () => { - middleware({ dispatch, getState })(jest.fn())({ + middleware({ dispatch, getState })(vi.fn())({ payload: fromPartial({ version: '1.2.3' }), type: 'something_else', }); diff --git a/test/servers/reducers/servers.test.ts b/test/servers/reducers/servers.test.ts index 17637483..890430df 100644 --- a/test/servers/reducers/servers.test.ts +++ b/test/servers/reducers/servers.test.ts @@ -15,7 +15,7 @@ describe('serversReducer', () => { def456: fromPartial({ id: 'def456' }), }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); describe('reducer', () => { it('returns edited server when action is EDIT_SERVER', () => diff --git a/test/servers/services/ServersExporter.test.ts b/test/servers/services/ServersExporter.test.ts index a50a5eeb..c077965f 100644 --- a/test/servers/services/ServersExporter.test.ts +++ b/test/servers/services/ServersExporter.test.ts @@ -5,7 +5,7 @@ import { appendChild, removeChild, windowMock } from '../../__mocks__/Window.moc describe('ServersExporter', () => { const storageMock = fromPartial({ - get: jest.fn(() => ({ + get: vi.fn(() => ({ abc123: { id: 'abc123', name: 'foo', @@ -18,16 +18,16 @@ describe('ServersExporter', () => { }, } as any)), }); - const erroneousToCsv = jest.fn(() => { + const erroneousToCsv = vi.fn(() => { throw new Error(''); }); - const createCsvjsonMock = (throwError = false) => (throwError ? erroneousToCsv : jest.fn(() => '')); + const createCsvjsonMock = (throwError = false) => (throwError ? erroneousToCsv : vi.fn(() => '')); - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); describe('exportServers', () => { let originalConsole: Console; - const error = jest.fn(); + const error = vi.fn(); beforeEach(() => { originalConsole = global.console; diff --git a/test/servers/services/ServersImporter.test.ts b/test/servers/services/ServersImporter.test.ts index be909a9c..f9554fa6 100644 --- a/test/servers/services/ServersImporter.test.ts +++ b/test/servers/services/ServersImporter.test.ts @@ -4,8 +4,8 @@ import { ServersImporter } from '../../../src/servers/services/ServersImporter'; describe('ServersImporter', () => { const servers: RegularServer[] = [fromPartial({}), fromPartial({})]; - const csvjsonMock = jest.fn().mockResolvedValue(servers); - const readAsText = jest.fn(); + const csvjsonMock = vi.fn().mockResolvedValue(servers); + const readAsText = vi.fn(); const fileReaderMock = fromPartial({ readAsText, addEventListener: ((_eventName: string, listener: (e: ProgressEvent) => void) => listener( @@ -14,7 +14,7 @@ describe('ServersImporter', () => { }); const importer = new ServersImporter(csvjsonMock, () => fileReaderMock); - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); describe('importServersFromFile', () => { it('rejects with error if no file was provided', async () => { diff --git a/test/settings/RealTimeUpdatesSettings.test.tsx b/test/settings/RealTimeUpdatesSettings.test.tsx index 63d2c65c..33e3da1b 100644 --- a/test/settings/RealTimeUpdatesSettings.test.tsx +++ b/test/settings/RealTimeUpdatesSettings.test.tsx @@ -7,8 +7,8 @@ import type { import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const toggleRealTimeUpdates = jest.fn(); - const setRealTimeUpdatesInterval = jest.fn(); + const toggleRealTimeUpdates = vi.fn(); + const setRealTimeUpdatesInterval = vi.fn(); const setUp = (realTimeUpdates: Partial = {}) => renderWithEvents( ', () => { />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders enabled real time updates as expected', () => { setUp({ enabled: true }); diff --git a/test/settings/ShortUrlCreationSettings.test.tsx b/test/settings/ShortUrlCreationSettings.test.tsx index 45dcd4b2..b1e1556e 100644 --- a/test/settings/ShortUrlCreationSettings.test.tsx +++ b/test/settings/ShortUrlCreationSettings.test.tsx @@ -5,7 +5,7 @@ import { ShortUrlCreationSettings } from '../../src/settings/ShortUrlCreationSet import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const setShortUrlCreationSettings = jest.fn(); + const setShortUrlCreationSettings = vi.fn(); const setUp = (shortUrlCreation?: ShortUrlsSettings) => renderWithEvents( ', () => { />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it.each([ [{ validateUrls: true }, true], diff --git a/test/settings/ShortUrlsListSettings.test.tsx b/test/settings/ShortUrlsListSettings.test.tsx index 889559f4..70b13942 100644 --- a/test/settings/ShortUrlsListSettings.test.tsx +++ b/test/settings/ShortUrlsListSettings.test.tsx @@ -6,12 +6,12 @@ import type { ShortUrlsOrder } from '../../src/short-urls/data'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const setSettings = jest.fn(); + const setSettings = vi.fn(); const setUp = (shortUrlsList?: ShortUrlsSettings) => renderWithEvents( , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it.each([ [undefined, 'Order by: Created at - DESC'], diff --git a/test/settings/TagsSettings.test.tsx b/test/settings/TagsSettings.test.tsx index c3bf1b20..cf0d165a 100644 --- a/test/settings/TagsSettings.test.tsx +++ b/test/settings/TagsSettings.test.tsx @@ -6,12 +6,12 @@ import type { TagsOrder } from '../../src/tags/data/TagsListChildrenProps'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const setTagsSettings = jest.fn(); + const setTagsSettings = vi.fn(); const setUp = (tags?: TagsSettingsOptions) => renderWithEvents( , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders expected amount of groups', () => { setUp(); diff --git a/test/settings/UserInterfaceSettings.test.tsx b/test/settings/UserInterfaceSettings.test.tsx index b0ecf856..dbf40d11 100644 --- a/test/settings/UserInterfaceSettings.test.tsx +++ b/test/settings/UserInterfaceSettings.test.tsx @@ -6,12 +6,12 @@ import type { Theme } from '../../src/utils/theme'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const setUiSettings = jest.fn(); + const setUiSettings = vi.fn(); const setUp = (ui?: UiSettings) => renderWithEvents( , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it.each([ [{ theme: 'dark' as Theme }, true], diff --git a/test/settings/VisitsSettings.test.tsx b/test/settings/VisitsSettings.test.tsx index 1bc729f4..2f9e01bf 100644 --- a/test/settings/VisitsSettings.test.tsx +++ b/test/settings/VisitsSettings.test.tsx @@ -5,12 +5,12 @@ import { VisitsSettings } from '../../src/settings/VisitsSettings'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const setVisitsSettings = jest.fn(); + const setVisitsSettings = vi.fn(); const setUp = (settings: Partial = {}) => renderWithEvents( , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders expected components', () => { setUp(); diff --git a/test/settings/__snapshots__/UserInterfaceSettings.test.tsx.snap b/test/settings/__snapshots__/UserInterfaceSettings.test.tsx.snap index d36b6cfa..07462087 100644 --- a/test/settings/__snapshots__/UserInterfaceSettings.test.tsx.snap +++ b/test/settings/__snapshots__/UserInterfaceSettings.test.tsx.snap @@ -1,4 +1,58 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > shows different icons based on theme 1`] = ` + +`; + +exports[` > shows different icons based on theme 2`] = ` + +`; + +exports[` > shows different icons based on theme 3`] = ` + +`; exports[` shows different icons based on theme 1`] = ` ', () => { const CreateShortUrlResult = () => CreateShortUrlResult; const shortUrlCreation = { validateUrls: true }; const shortUrlCreationResult = fromPartial({}); - const createShortUrl = jest.fn(async () => Promise.resolve()); + const createShortUrl = vi.fn(async () => Promise.resolve()); const CreateShortUrl = createShortUrlsCreator(ShortUrlForm, CreateShortUrlResult); const setUp = () => render( ', () => { selectedServer={null} shortUrlDetail={fromPartial(detail)} shortUrlEdition={fromPartial(edition)} - getShortUrlDetail={jest.fn()} - editShortUrl={jest.fn(async () => Promise.resolve())} + getShortUrlDetail={vi.fn()} + editShortUrl={vi.fn(async () => Promise.resolve())} /> , ); diff --git a/test/short-urls/ShortUrlForm.test.tsx b/test/short-urls/ShortUrlForm.test.tsx index 7d94b956..b8616e0e 100644 --- a/test/short-urls/ShortUrlForm.test.tsx +++ b/test/short-urls/ShortUrlForm.test.tsx @@ -10,7 +10,7 @@ import type { OptionalString } from '../../src/utils/utils'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const createShortUrl = jest.fn(async () => Promise.resolve()); + const createShortUrl = vi.fn(async () => Promise.resolve()); const ShortUrlForm = createShortUrlForm(() => TagsSelector, () => DomainSelector); const setUp = (selectedServer: SelectedServer = null, mode: Mode = 'create', title?: OptionalString) => renderWithEvents( @@ -23,7 +23,7 @@ describe('', () => { />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it.each([ [ diff --git a/test/short-urls/ShortUrlsFilteringBar.test.tsx b/test/short-urls/ShortUrlsFilteringBar.test.tsx index 24f00e63..ff2abb00 100644 --- a/test/short-urls/ShortUrlsFilteringBar.test.tsx +++ b/test/short-urls/ShortUrlsFilteringBar.test.tsx @@ -8,17 +8,17 @@ import { formatDate } from '../../src/utils/helpers/date'; import type { DateRange } from '../../src/utils/helpers/dateIntervals'; import { renderWithEvents } from '../__helpers__/setUpTest'; -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useParams: jest.fn().mockReturnValue({ serverId: '1' }), - useNavigate: jest.fn(), - useLocation: jest.fn().mockReturnValue({}), +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useParams: vi.fn().mockReturnValue({ serverId: '1' }), + useNavigate: vi.fn(), + useLocation: vi.fn().mockReturnValue({}), })); describe('', () => { const ShortUrlsFilteringBar = filteringBarCreator(() => <>ExportShortUrlsBtn, () => <>TagsSelector); - const navigate = jest.fn(); - const handleOrderBy = jest.fn(); + const navigate = vi.fn(); + const handleOrderBy = vi.fn(); const now = new Date(); const setUp = (search = '', selectedServer?: SelectedServer) => { (useLocation as any).mockReturnValue({ search }); @@ -36,7 +36,7 @@ describe('', () => { ); }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders expected children components', () => { setUp(); diff --git a/test/short-urls/ShortUrlsList.test.tsx b/test/short-urls/ShortUrlsList.test.tsx index 09b40042..d3d9cb51 100644 --- a/test/short-urls/ShortUrlsList.test.tsx +++ b/test/short-urls/ShortUrlsList.test.tsx @@ -10,17 +10,17 @@ import type { ShortUrlsTableType } from '../../src/short-urls/ShortUrlsTable'; import type { SemVer } from '../../src/utils/helpers/version'; import { renderWithEvents } from '../__helpers__/setUpTest'; -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: jest.fn().mockReturnValue(jest.fn()), - useLocation: jest.fn().mockReturnValue({ search: '?tags=test%20tag&search=example.com' }), +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useNavigate: vi.fn().mockReturnValue(vi.fn()), + useLocation: vi.fn().mockReturnValue({ search: '?tags=test%20tag&search=example.com' }), })); describe('', () => { const ShortUrlsTable: ShortUrlsTableType = ({ onTagClick }) => onTagClick?.('foo')}>ShortUrlsTable; const ShortUrlsFilteringBar = () => ShortUrlsFilteringBar; - const listShortUrlsMock = jest.fn(); - const navigate = jest.fn(); + const listShortUrlsMock = vi.fn(); + const navigate = vi.fn(); const shortUrlsList = fromPartial({ shortUrls: { data: [ @@ -51,7 +51,7 @@ describe('', () => { (useNavigate as any).mockReturnValue(navigate); }); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('wraps expected components', () => { setUp(); diff --git a/test/short-urls/ShortUrlsTable.test.tsx b/test/short-urls/ShortUrlsTable.test.tsx index 23d07a57..4c4370cb 100644 --- a/test/short-urls/ShortUrlsTable.test.tsx +++ b/test/short-urls/ShortUrlsTable.test.tsx @@ -9,13 +9,13 @@ import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const shortUrlsList = fromPartial({}); - const orderByColumn = jest.fn(); + const orderByColumn = vi.fn(); const ShortUrlsTable = shortUrlsTableCreator(() => ShortUrlsRow); const setUp = (server: SelectedServer = null) => renderWithEvents( orderByColumn} />, ); - afterEach(jest.resetAllMocks); + afterEach(vi.resetAllMocks); it('should render inner table by default', () => { setUp(); diff --git a/test/short-urls/helpers/CreateShortUrlResult.test.tsx b/test/short-urls/helpers/CreateShortUrlResult.test.tsx index 3293f822..62f11705 100644 --- a/test/short-urls/helpers/CreateShortUrlResult.test.tsx +++ b/test/short-urls/helpers/CreateShortUrlResult.test.tsx @@ -6,14 +6,14 @@ import type { TimeoutToggle } from '../../../src/utils/helpers/hooks'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const copyToClipboard = jest.fn(); - const useTimeoutToggle = jest.fn(() => [false, copyToClipboard]) as TimeoutToggle; + const copyToClipboard = vi.fn(); + const useTimeoutToggle = vi.fn(() => [false, copyToClipboard]) as TimeoutToggle; const CreateShortUrlResult = createResult(useTimeoutToggle); const setUp = (creation: ShortUrlCreation) => renderWithEvents( {}} creation={creation} />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders an error when error is true', () => { setUp({ error: true, saved: false, saving: false }); diff --git a/test/short-urls/helpers/DeleteShortUrlModal.test.tsx b/test/short-urls/helpers/DeleteShortUrlModal.test.tsx index 35671459..964c8207 100644 --- a/test/short-urls/helpers/DeleteShortUrlModal.test.tsx +++ b/test/short-urls/helpers/DeleteShortUrlModal.test.tsx @@ -14,8 +14,8 @@ describe('', () => { shortCode: 'abc123', longUrl: 'https://long-domain.com/foo/bar', }); - const deleteShortUrl = jest.fn().mockResolvedValue(undefined); - const shortUrlDeleted = jest.fn(); + const deleteShortUrl = vi.fn().mockResolvedValue(undefined); + const shortUrlDeleted = vi.fn(); const setUp = (shortUrlDeletion: Partial) => renderWithEvents( ( @@ -25,13 +25,13 @@ describe('', () => { shortUrlDeletion={fromPartial(shortUrlDeletion)} deleteShortUrl={deleteShortUrl} shortUrlDeleted={shortUrlDeleted} - resetDeleteShortUrl={jest.fn()} + resetDeleteShortUrl={vi.fn()} /> )} />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('shows generic error when non-threshold error occurs', () => { setUp({ diff --git a/test/short-urls/helpers/ExportShortUrlsBtn.test.tsx b/test/short-urls/helpers/ExportShortUrlsBtn.test.tsx index 2e8fb718..0a9dee10 100644 --- a/test/short-urls/helpers/ExportShortUrlsBtn.test.tsx +++ b/test/short-urls/helpers/ExportShortUrlsBtn.test.tsx @@ -8,9 +8,9 @@ import { ExportShortUrlsBtn as createExportShortUrlsBtn } from '../../../src/sho import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const listShortUrls = jest.fn(); - const buildShlinkApiClient = jest.fn().mockReturnValue({ listShortUrls }); - const exportShortUrls = jest.fn(); + const listShortUrls = vi.fn(); + const buildShlinkApiClient = vi.fn().mockReturnValue({ listShortUrls }); + const exportShortUrls = vi.fn(); const reportExporter = fromPartial({ exportShortUrls }); const ExportShortUrlsBtn = createExportShortUrlsBtn(buildShlinkApiClient, reportExporter); const setUp = (amount?: number, selectedServer?: SelectedServer) => renderWithEvents( @@ -19,7 +19,7 @@ describe('', () => { , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it.each([ [undefined, '0'], diff --git a/test/short-urls/helpers/QrCodeModal.test.tsx b/test/short-urls/helpers/QrCodeModal.test.tsx index 2a43b638..abbcad21 100644 --- a/test/short-urls/helpers/QrCodeModal.test.tsx +++ b/test/short-urls/helpers/QrCodeModal.test.tsx @@ -5,7 +5,7 @@ import type { SemVer } from '../../../src/utils/helpers/version'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const saveImage = jest.fn().mockReturnValue(Promise.resolve()); + const saveImage = vi.fn().mockReturnValue(Promise.resolve()); const QrCodeModal = createQrCodeModal(fromPartial({ saveImage })); const shortUrl = 'https://s.test/abc123'; const setUp = (version: SemVer = '2.8.0') => renderWithEvents( @@ -17,7 +17,7 @@ describe('', () => { />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('shows an external link to the URL in the header', () => { setUp(); diff --git a/test/short-urls/helpers/ShortUrlsFilterDropdown.test.tsx b/test/short-urls/helpers/ShortUrlsFilterDropdown.test.tsx index b1168b27..5861b77a 100644 --- a/test/short-urls/helpers/ShortUrlsFilterDropdown.test.tsx +++ b/test/short-urls/helpers/ShortUrlsFilterDropdown.test.tsx @@ -4,7 +4,7 @@ import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const setUp = (supportsDisabledFiltering: boolean) => renderWithEvents( - , + , ); it.each([ diff --git a/test/short-urls/helpers/ShortUrlsRow.test.tsx b/test/short-urls/helpers/ShortUrlsRow.test.tsx index 1d2cd884..5c9297a5 100644 --- a/test/short-urls/helpers/ShortUrlsRow.test.tsx +++ b/test/short-urls/helpers/ShortUrlsRow.test.tsx @@ -20,14 +20,14 @@ interface SetUpOptions { settings?: Partial; } -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useLocation: jest.fn().mockReturnValue({}), +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useLocation: vi.fn().mockReturnValue({}), })); describe('', () => { - const timeoutToggle = jest.fn(() => true); - const useTimeoutToggle = jest.fn(() => [false, timeoutToggle]) as TimeoutToggle; + const timeoutToggle = vi.fn(() => true); + const useTimeoutToggle = vi.fn(() => [false, timeoutToggle]) as TimeoutToggle; const server = fromPartial({ url: 'https://s.test' }); const shortUrl: ShortUrl = { shortCode: 'abc123', diff --git a/test/short-urls/helpers/__snapshots__/ShortUrlsRow.test.tsx.snap b/test/short-urls/helpers/__snapshots__/ShortUrlsRow.test.tsx.snap index dc4ad5a9..c9986524 100644 --- a/test/short-urls/helpers/__snapshots__/ShortUrlsRow.test.tsx.snap +++ b/test/short-urls/helpers/__snapshots__/ShortUrlsRow.test.tsx.snap @@ -1,4 +1,148 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > displays expected status icon 1`] = ` + +`; + +exports[` > displays expected status icon 2`] = ` + +`; + +exports[` > displays expected status icon 3`] = ` + +`; + +exports[` > displays expected status icon 4`] = ` + +`; + +exports[` > displays expected status icon 5`] = ` + +`; + +exports[` > displays expected status icon 6`] = ` + +`; + +exports[` > displays expected status icon 7`] = ` + +`; + +exports[` > displays expected status icon 8`] = ` + +`; exports[` displays expected status icon 1`] = ` ', () => { const initialErrorCorrection: QrErrorCorrection = 'Q'; - const setErrorCorrection = jest.fn(); + const setErrorCorrection = vi.fn(); const setUp = () => renderWithEvents( , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders initial state', async () => { const { user } = setUp(); diff --git a/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx b/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx index 41cb3975..657b672a 100644 --- a/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx +++ b/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx @@ -5,10 +5,10 @@ import { renderWithEvents } from '../../../__helpers__/setUpTest'; describe('', () => { const initialFormat: QrCodeFormat = 'svg'; - const setFormat = jest.fn(); + const setFormat = vi.fn(); const setUp = () => renderWithEvents(); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders initial state', async () => { const { user } = setUp(); diff --git a/test/short-urls/reducers/shortUrlCreation.test.ts b/test/short-urls/reducers/shortUrlCreation.test.ts index e1e14a9e..09107540 100644 --- a/test/short-urls/reducers/shortUrlCreation.test.ts +++ b/test/short-urls/reducers/shortUrlCreation.test.ts @@ -9,12 +9,12 @@ import { describe('shortUrlCreationReducer', () => { const shortUrl = fromPartial({}); - const createShortUrlCall = jest.fn(); + const createShortUrlCall = vi.fn(); const buildShlinkApiClient = () => fromPartial({ 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({}); it('calls API on success', async () => { diff --git a/test/short-urls/reducers/shortUrlDeletion.test.ts b/test/short-urls/reducers/shortUrlDeletion.test.ts index 74f7017b..0ee97d34 100644 --- a/test/short-urls/reducers/shortUrlDeletion.test.ts +++ b/test/short-urls/reducers/shortUrlDeletion.test.ts @@ -7,12 +7,12 @@ import { } from '../../../src/short-urls/reducers/shortUrlDeletion'; describe('shortUrlDeletionReducer', () => { - const deleteShortUrlCall = jest.fn(); + const deleteShortUrlCall = vi.fn(); const buildShlinkApiClient = () => fromPartial({ 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']], diff --git a/test/short-urls/reducers/shortUrlDetail.test.ts b/test/short-urls/reducers/shortUrlDetail.test.ts index 5aee45b2..97b5e177 100644 --- a/test/short-urls/reducers/shortUrlDetail.test.ts +++ b/test/short-urls/reducers/shortUrlDetail.test.ts @@ -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({ 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({ shortUrlsList }); it.each([ diff --git a/test/short-urls/reducers/shortUrlEdition.test.ts b/test/short-urls/reducers/shortUrlEdition.test.ts index e1f143f2..b00c53d7 100644 --- a/test/short-urls/reducers/shortUrlEdition.test.ts +++ b/test/short-urls/reducers/shortUrlEdition.test.ts @@ -11,12 +11,12 @@ describe('shortUrlEditionReducer', () => { const longUrl = 'https://shlink.io'; const shortCode = 'abc123'; const shortUrl = fromPartial({ 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({ 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(), {}); diff --git a/test/short-urls/reducers/shortUrlsList.test.ts b/test/short-urls/reducers/shortUrlsList.test.ts index 2954ac8f..f5dba798 100644 --- a/test/short-urls/reducers/shortUrlsList.test.ts +++ b/test/short-urls/reducers/shortUrlsList.test.ts @@ -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({ 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({}); diff --git a/test/tags/TagsList.test.tsx b/test/tags/TagsList.test.tsx index f486054b..4d79823d 100644 --- a/test/tags/TagsList.test.tsx +++ b/test/tags/TagsList.test.tsx @@ -8,7 +8,7 @@ import { TagsList as createTagsList } from '../../src/tags/TagsList'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const filterTags = jest.fn(); + const filterTags = vi.fn(); const TagsListComp = createTagsList(({ sortedTags }) => <>TagsTable ({sortedTags.map((t) => t.visits).join(',')})); const setUp = (tagsList: Partial, excludeBots = false) => renderWithEvents( ', () => { />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('shows a loading message when tags are being loaded', () => { setUp({ loading: true }); diff --git a/test/tags/TagsTable.test.tsx b/test/tags/TagsTable.test.tsx index ad41c4ce..fcf82063 100644 --- a/test/tags/TagsTable.test.tsx +++ b/test/tags/TagsTable.test.tsx @@ -5,10 +5,13 @@ import { TagsTable as createTagsTable } from '../../src/tags/TagsTable'; import { rangeOf } from '../../src/utils/utils'; import { renderWithEvents } from '../__helpers__/setUpTest'; -jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useLocation: jest.fn() })); +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useLocation: vi.fn(), +})); describe('', () => { - const orderByColumn = jest.fn(); + const orderByColumn = vi.fn(); const TagsTable = createTagsTable(({ tag }) => TagsTableRow [{tag.tag}]); const tags = (amount: number) => rangeOf(amount, (i) => `tag_${i}`); const setUp = (sortedTags: string[] = [], search = '') => { @@ -23,7 +26,7 @@ describe('', () => { ); }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders empty result if there are no tags', () => { setUp(); diff --git a/test/tags/helpers/DeleteTagConfirmModal.test.tsx b/test/tags/helpers/DeleteTagConfirmModal.test.tsx index 55493087..fc5fd1ec 100644 --- a/test/tags/helpers/DeleteTagConfirmModal.test.tsx +++ b/test/tags/helpers/DeleteTagConfirmModal.test.tsx @@ -5,20 +5,20 @@ import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const tag = 'nodejs'; - const deleteTag = jest.fn(); - const toggle = jest.fn(); + const deleteTag = vi.fn(); + const toggle = vi.fn(); const setUp = (tagDelete: TagDeletion) => renderWithEvents( , ); - afterEach(jest.resetAllMocks); + afterEach(vi.resetAllMocks); it('asks confirmation for provided tag to be deleted', () => { setUp({ error: false, deleted: false, deleting: false }); diff --git a/test/tags/helpers/EditTagModal.test.tsx b/test/tags/helpers/EditTagModal.test.tsx index 674f4fd5..d4262c53 100644 --- a/test/tags/helpers/EditTagModal.test.tsx +++ b/test/tags/helpers/EditTagModal.test.tsx @@ -5,17 +5,17 @@ import type { TagEdition } from '../../../src/tags/reducers/tagEdit'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const EditTagModal = createEditTagModal(fromPartial({ getColorForKey: jest.fn(() => 'green') })); - const editTag = jest.fn().mockReturnValue(Promise.resolve()); - const toggle = jest.fn(); + const EditTagModal = createEditTagModal(fromPartial({ getColorForKey: vi.fn(() => 'green') })); + const editTag = vi.fn().mockReturnValue(Promise.resolve()); + const toggle = vi.fn(); const setUp = (tagEdit: Partial = {}) => { const edition = fromPartial(tagEdit); return renderWithEvents( - , + , ); }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('allows modal to be toggled with different mechanisms', async () => { const { user } = setUp(); diff --git a/test/tags/helpers/Tag.test.tsx b/test/tags/helpers/Tag.test.tsx index d754aebd..783775ed 100644 --- a/test/tags/helpers/Tag.test.tsx +++ b/test/tags/helpers/Tag.test.tsx @@ -20,10 +20,10 @@ const hexToRgb = (hex: string) => { }; describe('', () => { - const onClick = jest.fn(); - const onClose = jest.fn(); - const isColorLightForKey = jest.fn(() => false); - const getColorForKey = jest.fn(() => MAIN_COLOR); + const onClick = vi.fn(); + const onClose = vi.fn(); + const isColorLightForKey = vi.fn(() => false); + const getColorForKey = vi.fn(() => MAIN_COLOR); const colorGenerator = fromPartial({ getColorForKey, isColorLightForKey }); const setUp = (text: string, clearable?: boolean, children?: ReactNode) => renderWithEvents( @@ -31,7 +31,7 @@ describe('', () => { , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it.each([ [true], diff --git a/test/tags/helpers/TagsSelector.test.tsx b/test/tags/helpers/TagsSelector.test.tsx index f0a6fd3a..ad95f239 100644 --- a/test/tags/helpers/TagsSelector.test.tsx +++ b/test/tags/helpers/TagsSelector.test.tsx @@ -6,7 +6,7 @@ import { renderWithEvents } from '../../__helpers__/setUpTest'; import { colorGeneratorMock } from '../../utils/services/__mocks__/ColorGenerator.mock'; describe('', () => { - const onChange = jest.fn(); + const onChange = vi.fn(); const TagsSelector = createTagsSelector(colorGeneratorMock); const tags = ['foo', 'bar']; const tagsList = fromPartial({ tags: [...tags, 'baz'] }); @@ -15,12 +15,12 @@ describe('', () => { selectedTags={tags} tagsList={tagsList} settings={fromPartial({})} - listTags={jest.fn()} + listTags={vi.fn()} onChange={onChange} />, ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('has an input for tags', () => { setUp(); diff --git a/test/tags/reducers/tagDelete.test.ts b/test/tags/reducers/tagDelete.test.ts index 640cd88c..38db9d88 100644 --- a/test/tags/reducers/tagDelete.test.ts +++ b/test/tags/reducers/tagDelete.test.ts @@ -4,11 +4,11 @@ import type { ShlinkState } from '../../../src/container/types'; import { tagDeleted, tagDeleteReducerCreator } from '../../../src/tags/reducers/tagDelete'; describe('tagDeleteReducer', () => { - const deleteTagsCall = jest.fn(); + const deleteTagsCall = vi.fn(); const buildShlinkApiClient = () => fromPartial({ deleteTags: deleteTagsCall }); const { reducer, deleteTag } = tagDeleteReducerCreator(buildShlinkApiClient); - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); describe('reducer', () => { it('returns loading on DELETE_TAG_START', () => { @@ -43,7 +43,7 @@ describe('tagDeleteReducer', () => { }); describe('deleteTag', () => { - const dispatch = jest.fn(); + const dispatch = vi.fn(); const getState = () => fromPartial({}); it('calls API on success', async () => { diff --git a/test/tags/reducers/tagEdit.test.ts b/test/tags/reducers/tagEdit.test.ts index f5b4426c..cba58980 100644 --- a/test/tags/reducers/tagEdit.test.ts +++ b/test/tags/reducers/tagEdit.test.ts @@ -8,9 +8,9 @@ describe('tagEditReducer', () => { const oldName = 'foo'; const newName = 'bar'; const color = '#ff0000'; - const editTagCall = jest.fn(); + const editTagCall = vi.fn(); const buildShlinkApiClient = () => fromPartial({ editTag: editTagCall }); - const colorGenerator = fromPartial({ setColorForKey: jest.fn() }); + const colorGenerator = fromPartial({ setColorForKey: vi.fn() }); const editTag = editTagCreator(buildShlinkApiClient, colorGenerator); const { reducer } = tagEditReducerCreator(editTag); @@ -50,10 +50,10 @@ describe('tagEditReducer', () => { }); describe('editTag', () => { - const dispatch = jest.fn(); + const dispatch = vi.fn(); const getState = () => fromPartial({}); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('calls API on success', async () => { editTagCall.mockResolvedValue(undefined); diff --git a/test/tags/reducers/tagsList.test.ts b/test/tags/reducers/tagsList.test.ts index 09936db2..230d024e 100644 --- a/test/tags/reducers/tagsList.test.ts +++ b/test/tags/reducers/tagsList.test.ts @@ -16,12 +16,12 @@ import type { CreateVisit } from '../../../src/visits/types'; describe('tagsListReducer', () => { const state = (props: Partial) => fromPartial(props); - const buildShlinkApiClient = jest.fn(); + const buildShlinkApiClient = vi.fn(); const listTags = listTagsCreator(buildShlinkApiClient, true); const createShortUrl = createShortUrlCreator(buildShlinkApiClient); const { reducer } = tagsListReducerCreator(listTags, createShortUrl); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); describe('reducer', () => { it('returns loading on LIST_TAGS_START', () => { @@ -196,9 +196,9 @@ describe('tagsListReducer', () => { }); describe('listTags', () => { - const dispatch = jest.fn(); - const getState = jest.fn(() => fromPartial({})); - const listTagsMock = jest.fn(); + const dispatch = vi.fn(); + const getState = vi.fn(() => fromPartial({})); + const listTagsMock = vi.fn(); const assertNoAction = async (tagsList: TagsList) => { getState.mockReturnValue(fromPartial({ tagsList })); diff --git a/test/utils/Checkbox.test.tsx b/test/utils/Checkbox.test.tsx index d290b319..09c248be 100644 --- a/test/utils/Checkbox.test.tsx +++ b/test/utils/Checkbox.test.tsx @@ -24,7 +24,7 @@ describe('', () => { }); it.each([[true], [false]])('changes checked status on input change', async (checked) => { - const onChange = jest.fn(); + const onChange = vi.fn(); const { user } = renderWithEvents(Foo); expect(onChange).not.toHaveBeenCalled(); diff --git a/test/utils/CopyToClipboardIcon.test.tsx b/test/utils/CopyToClipboardIcon.test.tsx index 3423a3d9..2b0c625f 100644 --- a/test/utils/CopyToClipboardIcon.test.tsx +++ b/test/utils/CopyToClipboardIcon.test.tsx @@ -2,10 +2,10 @@ import { CopyToClipboardIcon } from '../../src/utils/CopyToClipboardIcon'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const onCopy = jest.fn(); + const onCopy = vi.fn(); const setUp = (text = 'foo') => renderWithEvents(); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('wraps expected components', () => { const { container } = setUp(); diff --git a/test/utils/DropdownBtnMenu.test.tsx b/test/utils/DropdownBtnMenu.test.tsx index 22741fde..a15244ea 100644 --- a/test/utils/DropdownBtnMenu.test.tsx +++ b/test/utils/DropdownBtnMenu.test.tsx @@ -6,7 +6,7 @@ import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setUp = (props: Partial = {}) => renderWithEvents( - ({ toggle: jest.fn(), ...props })}> + ({ toggle: vi.fn(), ...props })}> the children , ); diff --git a/test/utils/OrderingDropdown.test.tsx b/test/utils/OrderingDropdown.test.tsx index 71660353..56ecba33 100644 --- a/test/utils/OrderingDropdown.test.tsx +++ b/test/utils/OrderingDropdown.test.tsx @@ -12,7 +12,7 @@ describe('', () => { baz: 'Hello World', }; const setUp = (props: Partial = {}) => renderWithEvents( - , + , ); const setUpWithDisplayedMenu = async (props: Partial = {}) => { const result = setUp(props); @@ -65,7 +65,7 @@ describe('', () => { ])( 'triggers change with proper params depending on clicked item and initial state', async (initialOrder, expectedNewField, expectedNewDir) => { - const onChange = jest.fn(); + const onChange = vi.fn(); const { user } = await setUpWithDisplayedMenu({ onChange, order: initialOrder }); await user.click(screen.getAllByRole('menuitem')[0]); @@ -76,7 +76,7 @@ describe('', () => { ); it('clears selection when last item is clicked', async () => { - const onChange = jest.fn(); + const onChange = vi.fn(); const { user } = await setUpWithDisplayedMenu({ onChange, order: { field: 'baz', dir: 'ASC' } }); await user.click(screen.getAllByRole('menuitem')[3]); diff --git a/test/utils/PaginationDropdown.test.tsx b/test/utils/PaginationDropdown.test.tsx index 02ff5d61..03551714 100644 --- a/test/utils/PaginationDropdown.test.tsx +++ b/test/utils/PaginationDropdown.test.tsx @@ -3,7 +3,7 @@ import { PaginationDropdown } from '../../src/utils/PaginationDropdown'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const setValue = jest.fn(); + const setValue = vi.fn(); const setUp = async () => { const result = renderWithEvents(); const { user } = result; @@ -13,7 +13,7 @@ describe('', () => { return result; }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders expected amount of items', async () => { await setUp(); diff --git a/test/utils/__snapshots__/CopyToClipboardIcon.test.tsx.snap b/test/utils/__snapshots__/CopyToClipboardIcon.test.tsx.snap index 27dc438a..cbbe8016 100644 --- a/test/utils/__snapshots__/CopyToClipboardIcon.test.tsx.snap +++ b/test/utils/__snapshots__/CopyToClipboardIcon.test.tsx.snap @@ -1,4 +1,24 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > wraps expected components 1`] = ` +
+ +
+`; exports[` wraps expected components 1`] = `
diff --git a/test/utils/__snapshots__/ExportBtn.test.tsx.snap b/test/utils/__snapshots__/ExportBtn.test.tsx.snap index 466ba0f7..6b663ec8 100644 --- a/test/utils/__snapshots__/ExportBtn.test.tsx.snap +++ b/test/utils/__snapshots__/ExportBtn.test.tsx.snap @@ -1,4 +1,22 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders expected icon 1`] = ` + +`; exports[` renders expected icon 1`] = ` > displays provided icon 1`] = ` +
+
+ + +
+
+`; + +exports[` > displays provided icon 2`] = ` +
+
+ + +
+
+`; + +exports[` > displays provided icon 3`] = ` +
+
+ + +
+
+`; exports[` displays provided icon 1`] = `
diff --git a/test/utils/dates/DateIntervalDropdownItems.test.tsx b/test/utils/dates/DateIntervalDropdownItems.test.tsx index 7b56930d..fdede1c0 100644 --- a/test/utils/dates/DateIntervalDropdownItems.test.tsx +++ b/test/utils/dates/DateIntervalDropdownItems.test.tsx @@ -6,7 +6,7 @@ import { DATE_INTERVALS, rangeOrIntervalToString } from '../../../src/utils/help import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const onChange = jest.fn(); + const onChange = vi.fn(); const setUp = async () => { const { user, ...renderResult } = renderWithEvents( @@ -20,7 +20,7 @@ describe('', () => { return { user, ...renderResult }; }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders expected amount of items', async () => { await setUp(); diff --git a/test/utils/dates/DateIntervalSelector.test.tsx b/test/utils/dates/DateIntervalSelector.test.tsx index 75b995bb..1e40164b 100644 --- a/test/utils/dates/DateIntervalSelector.test.tsx +++ b/test/utils/dates/DateIntervalSelector.test.tsx @@ -6,7 +6,7 @@ import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const activeInterval: DateInterval = 'last7Days'; - const onChange = jest.fn(); + const onChange = vi.fn(); const setUp = () => renderWithEvents( , ); diff --git a/test/utils/dates/DateRangeRow.test.tsx b/test/utils/dates/DateRangeRow.test.tsx index a4ab3e70..0f71f5af 100644 --- a/test/utils/dates/DateRangeRow.test.tsx +++ b/test/utils/dates/DateRangeRow.test.tsx @@ -3,13 +3,13 @@ import { DateRangeRow } from '../../../src/utils/dates/DateRangeRow'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const onEndDateChange = jest.fn(); - const onStartDateChange = jest.fn(); + const onEndDateChange = vi.fn(); + const onStartDateChange = vi.fn(); const setUp = () => renderWithEvents( , ); - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders two date inputs', () => { setUp(); diff --git a/test/utils/dates/DateRangeSelector.test.tsx b/test/utils/dates/DateRangeSelector.test.tsx index 08047483..09ee3c16 100644 --- a/test/utils/dates/DateRangeSelector.test.tsx +++ b/test/utils/dates/DateRangeSelector.test.tsx @@ -6,7 +6,7 @@ import type { DateInterval } from '../../../src/utils/helpers/dateIntervals'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const onDatesChange = jest.fn(); + const onDatesChange = vi.fn(); const setUp = async (props: Partial = {}) => { const result = renderWithEvents( ', () => { return result; }; - afterEach(jest.clearAllMocks); + afterEach(vi.clearAllMocks); it('renders proper amount of items', async () => { const { container } = await setUp(); diff --git a/test/utils/services/ColorGenerator.test.ts b/test/utils/services/ColorGenerator.test.ts index 50c85b0c..6b2dcd4c 100644 --- a/test/utils/services/ColorGenerator.test.ts +++ b/test/utils/services/ColorGenerator.test.ts @@ -6,12 +6,12 @@ import { MAIN_COLOR } from '../../../src/utils/theme'; describe('ColorGenerator', () => { let colorGenerator: ColorGenerator; const storageMock = fromPartial({ - set: jest.fn(), - get: jest.fn(), + set: vi.fn(), + get: vi.fn(), }); beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); colorGenerator = new ColorGenerator(storageMock); }); diff --git a/test/utils/services/LocalStorage.test.ts b/test/utils/services/LocalStorage.test.ts index dd866efa..c8b94b6a 100644 --- a/test/utils/services/LocalStorage.test.ts +++ b/test/utils/services/LocalStorage.test.ts @@ -2,13 +2,13 @@ import { fromPartial } from '@total-typescript/shoehorn'; import { LocalStorage } from '../../../src/utils/services/LocalStorage'; describe('LocalStorage', () => { - const getItem = jest.fn((key) => (key === 'shlink.foo' ? JSON.stringify({ foo: 'bar' }) : null)); - const setItem = jest.fn(); + const getItem = vi.fn((key) => (key === 'shlink.foo' ? JSON.stringify({ foo: 'bar' }) : null)); + const setItem = vi.fn(); const localStorageMock = fromPartial({ getItem, setItem }); let storage: LocalStorage; beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); storage = new LocalStorage(localStorageMock); }); diff --git a/test/utils/services/__mocks__/ColorGenerator.mock.ts b/test/utils/services/__mocks__/ColorGenerator.mock.ts index 2c68c4d6..d898575d 100644 --- a/test/utils/services/__mocks__/ColorGenerator.mock.ts +++ b/test/utils/services/__mocks__/ColorGenerator.mock.ts @@ -2,7 +2,7 @@ import { fromPartial } from '@total-typescript/shoehorn'; import type { ColorGenerator } from '../../../../src/utils/services/ColorGenerator'; export const colorGeneratorMock = fromPartial({ - getColorForKey: jest.fn(() => 'red'), - setColorForKey: jest.fn(), - isColorLightForKey: jest.fn(() => false), + getColorForKey: vi.fn(() => 'red'), + setColorForKey: vi.fn(), + isColorLightForKey: vi.fn(() => false), }); diff --git a/test/utils/table/__snapshots__/TableOrderIcon.test.tsx.snap b/test/utils/table/__snapshots__/TableOrderIcon.test.tsx.snap index b5a3a467..2a858f2c 100644 --- a/test/utils/table/__snapshots__/TableOrderIcon.test.tsx.snap +++ b/test/utils/table/__snapshots__/TableOrderIcon.test.tsx.snap @@ -1,4 +1,40 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders an icon when all conditions are met 1`] = ` + +`; + +exports[` > renders an icon when all conditions are met 2`] = ` + +`; exports[` renders an icon when all conditions are met 1`] = ` ({ - ...jest.requireActual('react-router-dom'), - useParams: jest.fn().mockReturnValue({ domain: 'foo.com_DEFAULT' }), +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useParams: vi.fn().mockReturnValue({ domain: 'foo.com_DEFAULT' }), })); describe('', () => { - const exportVisits = jest.fn(); - const getDomainVisits = jest.fn(); - const cancelGetDomainVisits = jest.fn(); + const exportVisits = vi.fn(); + const getDomainVisits = vi.fn(); + const cancelGetDomainVisits = vi.fn(); const domainVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); const DomainVisits = createDomainVisits(fromPartial({ exportVisits })); const setUp = () => renderWithEvents( diff --git a/test/visits/NonOrphanVisits.test.tsx b/test/visits/NonOrphanVisits.test.tsx index c60160ff..fb024b52 100644 --- a/test/visits/NonOrphanVisits.test.tsx +++ b/test/visits/NonOrphanVisits.test.tsx @@ -8,9 +8,9 @@ import type { VisitsInfo } from '../../src/visits/reducers/types'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const exportVisits = jest.fn(); - const getNonOrphanVisits = jest.fn(); - const cancelGetNonOrphanVisits = jest.fn(); + const exportVisits = vi.fn(); + const getNonOrphanVisits = vi.fn(); + const cancelGetNonOrphanVisits = vi.fn(); const nonOrphanVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); const NonOrphanVisits = createNonOrphanVisits(fromPartial({ exportVisits })); const setUp = () => renderWithEvents( diff --git a/test/visits/OrphanVisits.test.tsx b/test/visits/OrphanVisits.test.tsx index 87f46f72..53bad336 100644 --- a/test/visits/OrphanVisits.test.tsx +++ b/test/visits/OrphanVisits.test.tsx @@ -8,8 +8,8 @@ import type { VisitsInfo } from '../../src/visits/reducers/types'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const getOrphanVisits = jest.fn(); - const exportVisits = jest.fn(); + const getOrphanVisits = vi.fn(); + const exportVisits = vi.fn(); const orphanVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); const OrphanVisits = createOrphanVisits(fromPartial({ exportVisits })); const setUp = () => renderWithEvents( @@ -18,7 +18,7 @@ describe('', () => { {...fromPartial({ mercureInfo: {} })} getOrphanVisits={getOrphanVisits} orphanVisits={orphanVisits} - cancelGetOrphanVisits={jest.fn()} + cancelGetOrphanVisits={vi.fn()} settings={fromPartial({})} /> , diff --git a/test/visits/ShortUrlVisits.test.tsx b/test/visits/ShortUrlVisits.test.tsx index b36dadbe..cf6014a9 100644 --- a/test/visits/ShortUrlVisits.test.tsx +++ b/test/visits/ShortUrlVisits.test.tsx @@ -10,8 +10,8 @@ import { ShortUrlVisits as createShortUrlVisits } from '../../src/visits/ShortUr import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const getShortUrlVisitsMock = jest.fn(); - const exportVisits = jest.fn(); + const getShortUrlVisitsMock = vi.fn(); + const exportVisits = vi.fn(); const shortUrlVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); const ShortUrlVisits = createShortUrlVisits(fromPartial({ exportVisits })); const setUp = () => renderWithEvents( diff --git a/test/visits/ShortUrlVisitsHeader.test.tsx b/test/visits/ShortUrlVisitsHeader.test.tsx index a9ec7756..12863cee 100644 --- a/test/visits/ShortUrlVisitsHeader.test.tsx +++ b/test/visits/ShortUrlVisitsHeader.test.tsx @@ -12,7 +12,7 @@ describe('', () => { const shortUrlVisits = fromPartial({ visits: [{}, {}, {}], }); - const goBack = jest.fn(); + const goBack = vi.fn(); const setUp = (title?: string | null) => { const shortUrlDetail = fromPartial({ shortUrl: { diff --git a/test/visits/TagVisits.test.tsx b/test/visits/TagVisits.test.tsx index 492fb577..72b28df3 100644 --- a/test/visits/TagVisits.test.tsx +++ b/test/visits/TagVisits.test.tsx @@ -1,21 +1,21 @@ import { screen } from '@testing-library/react'; import { fromPartial } from '@total-typescript/shoehorn'; import { formatISO } from 'date-fns'; -import { MemoryRouter } from 'react-router-dom'; +import { MemoryRouter } from 'react-router'; import type { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; import type { TagVisits as TagVisitsStats } from '../../src/visits/reducers/tagVisits'; import type { TagVisitsProps } from '../../src/visits/TagVisits'; import { TagVisits as createTagVisits } from '../../src/visits/TagVisits'; import { renderWithEvents } from '../__helpers__/setUpTest'; -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useParams: jest.fn().mockReturnValue({ tag: 'foo' }), +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useParams: vi.fn().mockReturnValue({ tag: 'foo' }), })); describe('', () => { - const getTagVisitsMock = jest.fn(); - const exportVisits = jest.fn(); + const getTagVisitsMock = vi.fn(); + const exportVisits = vi.fn(); const tagVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); const TagVisits = createTagVisits( fromPartial({ isColorLightForKey: () => false, getColorForKey: () => 'red' }), diff --git a/test/visits/TagVisitsHeader.test.tsx b/test/visits/TagVisitsHeader.test.tsx index 1905d121..6c936c44 100644 --- a/test/visits/TagVisitsHeader.test.tsx +++ b/test/visits/TagVisitsHeader.test.tsx @@ -9,7 +9,7 @@ describe('', () => { tag: 'foo', visits: [{}, {}, {}, {}], }); - const goBack = jest.fn(); + const goBack = vi.fn(); const colorGenerator = fromPartial({ isColorLightForKey: () => false, getColorForKey: () => 'red' }); const setUp = () => render(); diff --git a/test/visits/VisitsHeader.test.tsx b/test/visits/VisitsHeader.test.tsx index 64887d20..b2131af3 100644 --- a/test/visits/VisitsHeader.test.tsx +++ b/test/visits/VisitsHeader.test.tsx @@ -6,7 +6,7 @@ import { VisitsHeader } from '../../src/visits/VisitsHeader'; describe('', () => { const visits: Visit[] = [fromPartial({}), fromPartial({}), fromPartial({})]; const title = 'My header title'; - const goBack = jest.fn(); + const goBack = vi.fn(); const setUp = () => render(); it('shows the amount of visits', () => { diff --git a/test/visits/VisitsStats.test.tsx b/test/visits/VisitsStats.test.tsx index eb8cc1b8..f5ce5702 100644 --- a/test/visits/VisitsStats.test.tsx +++ b/test/visits/VisitsStats.test.tsx @@ -10,8 +10,8 @@ import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const visits = rangeOf(3, () => fromPartial({ date: '2020-01-01' })); - const getVisitsMock = jest.fn(); - const exportCsv = jest.fn(); + const getVisitsMock = vi.fn(); + const exportCsv = vi.fn(); const setUp = (visitsInfo: Partial, activeRoute = '/by-time') => { const history = createMemoryHistory(); history.push(activeRoute); diff --git a/test/visits/VisitsTable.test.tsx b/test/visits/VisitsTable.test.tsx index eb59deda..d35587f5 100644 --- a/test/visits/VisitsTable.test.tsx +++ b/test/visits/VisitsTable.test.tsx @@ -8,7 +8,7 @@ import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const matchMedia = () => fromPartial({ matches: false }); - const setSelectedVisits = jest.fn(); + const setSelectedVisits = vi.fn(); const setUpFactory = (props: Partial = {}) => renderWithEvents( ', () => { ], }); - afterEach(jest.resetAllMocks); + afterEach(vi.resetAllMocks); it('renders expected amount of columns', () => { setUp([], []); diff --git a/test/visits/charts/__snapshots__/DoughnutChart.test.tsx.snap b/test/visits/charts/__snapshots__/DoughnutChart.test.tsx.snap index 2bfc371b..2cbe79aa 100644 --- a/test/visits/charts/__snapshots__/DoughnutChart.test.tsx.snap +++ b/test/visits/charts/__snapshots__/DoughnutChart.test.tsx.snap @@ -1,4 +1,28 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders Doughnut with expected props 1`] = ` +[ + { + "props": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "setTransform", + }, +] +`; exports[` renders Doughnut with expected props 1`] = ` [ diff --git a/test/visits/charts/__snapshots__/HorizontalBarChart.test.tsx.snap b/test/visits/charts/__snapshots__/HorizontalBarChart.test.tsx.snap index 28b01a3f..7d7beed3 100644 --- a/test/visits/charts/__snapshots__/HorizontalBarChart.test.tsx.snap +++ b/test/visits/charts/__snapshots__/HorizontalBarChart.test.tsx.snap @@ -1,4 +1,524 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders chart with expected canvas 1`] = ` +[ + { + "props": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "setTransform", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "foo", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "bar", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "0", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "500", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, +] +`; + +exports[` > renders chart with expected canvas 2`] = ` +[ + { + "props": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "setTransform", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "one", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "two", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "0", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "200,000", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, +] +`; + +exports[` > renders chart with expected canvas 3`] = ` +[ + { + "props": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "setTransform", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "one", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "two", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "max", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "0", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "200,000", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, +] +`; exports[` renders chart with expected canvas 1`] = ` [ diff --git a/test/visits/charts/__snapshots__/LineChartCard.test.tsx.snap b/test/visits/charts/__snapshots__/LineChartCard.test.tsx.snap index 6e049e38..a385f471 100644 --- a/test/visits/charts/__snapshots__/LineChartCard.test.tsx.snap +++ b/test/visits/charts/__snapshots__/LineChartCard.test.tsx.snap @@ -1,4 +1,464 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders chart with expected data 1`] = ` +[ + { + "props": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "setTransform", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "0", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "1", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, +] +`; + +exports[` > renders chart with expected data 2`] = ` +[ + { + "props": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "setTransform", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "0", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "1", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, +] +`; + +exports[` > renders chart with expected data 3`] = ` +[ + { + "props": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "setTransform", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "0", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "1", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "2016-04", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, +] +`; + +exports[` > renders chart with expected data 4`] = ` +[ + { + "props": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "setTransform", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "0", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "1", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, + { + "props": { + "text": "2016-04", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "measureText", + }, + { + "props": { + "value": "12px \\"Helvetica Neue\\", 'Helvetica', 'Arial', sans-serif", + }, + "transform": [ + 1, + 0, + 0, + 1, + 0, + 0, + ], + "type": "font", + }, +] +`; exports[` renders chart with expected data 1`] = ` [ diff --git a/test/visits/charts/__snapshots__/SortableBarChartCard.test.tsx.snap b/test/visits/charts/__snapshots__/SortableBarChartCard.test.tsx.snap index 175b4f45..ae4bf902 100644 --- a/test/visits/charts/__snapshots__/SortableBarChartCard.test.tsx.snap +++ b/test/visits/charts/__snapshots__/SortableBarChartCard.test.tsx.snap @@ -1,4 +1,1234 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders properly ordered stats when ordering is set 1`] = ` +
+
+ Foo +
+ +
+
+ +
+
+`; + +exports[` > renders properly ordered stats when ordering is set 2`] = ` +
+
+ Foo +
+ +
+
+ +
+
+`; + +exports[` > renders properly ordered stats when ordering is set 3`] = ` +
+
+ Foo +
+ +
+
+ +
+
+`; + +exports[` > renders properly ordered stats when ordering is set 4`] = ` +
+
+ Foo +
+ +
+
+ +
+
+`; + +exports[` > renders properly paginated stats when pagination is set 1`] = ` +
+
+ Foo +
+ +
+ +
+
+ +
+ +
+`; + +exports[` > renders properly paginated stats when pagination is set 2`] = ` +
+
+ Foo +
+ +
+ +
+
+ +
+ +
+`; + +exports[` > renders properly paginated stats when pagination is set 3`] = ` +
+
+ Foo +
+ +
+ +
+
+ +
+
+`; + +exports[` > renders properly paginated stats when pagination is set 4`] = ` +
+
+ Foo +
+ +
+ +
+
+ +
+
+`; + +exports[` > renders stats unchanged when no ordering is set 1`] = ` +
+
+ Foo +
+ +
+
+ +
+
+`; exports[` renders properly ordered stats when ordering is set 1`] = `
', () => { - const toggle = jest.fn(); + const toggle = vi.fn(); const zaragozaLat = 41.6563497; const zaragozaLong = -0.876566; const newYorkLat = 40.730610; diff --git a/test/visits/helpers/VisitsFilterDropdown.test.tsx b/test/visits/helpers/VisitsFilterDropdown.test.tsx index 1008d80e..2cab4ceb 100644 --- a/test/visits/helpers/VisitsFilterDropdown.test.tsx +++ b/test/visits/helpers/VisitsFilterDropdown.test.tsx @@ -4,7 +4,7 @@ import type { OrphanVisitType, VisitsFilter } from '../../../src/visits/types'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const onChange = jest.fn(); + const onChange = vi.fn(); const setUp = (selected: VisitsFilter = {}, isOrphanVisits = true) => renderWithEvents( ', () => { />, ); - beforeEach(jest.clearAllMocks); + beforeEach(vi.clearAllMocks); it('has expected text', () => { setUp(); diff --git a/test/visits/helpers/__snapshots__/MapModal.test.tsx.snap b/test/visits/helpers/__snapshots__/MapModal.test.tsx.snap index 9a95d69d..6492c497 100644 --- a/test/visits/helpers/__snapshots__/MapModal.test.tsx.snap +++ b/test/visits/helpers/__snapshots__/MapModal.test.tsx.snap @@ -1,4 +1,186 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders expected map 1`] = ` +