Fix incorrect types between testing library and vitest

This commit is contained in:
Alejandro Celaya 2023-05-27 12:29:03 +02:00
parent 12a05b422d
commit d14aea708e
77 changed files with 69 additions and 206 deletions

View file

@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org).
## [Unreleased]
### Added
* *Nothing*
### Changed
* [#781](https://github.com/shlinkio/shlink-web-client/issues/781) Migrate tests from jest to vitest.
### Deprecated
* *Nothing*
### Removed
* *Nothing*
### Fixed
* *Nothing*
## [3.10.1] - 2023-04-23
### Added
* *Nothing*

View file

@ -1,16 +1,23 @@
import 'vitest-canvas-mock';
import 'chart.js/auto';
import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';
import matchers from '@testing-library/jest-dom/matchers';
import { cleanup } from '@testing-library/react';
import { setAutoFreeze } from 'immer';
import ResizeObserver from 'resize-observer-polyfill';
import { afterEach, expect } from 'vitest';
// extends Vitest's expect method with methods from react-testing-library
// Workaround for TypeScript error: https://github.com/testing-library/jest-dom/issues/439#issuecomment-1536524120
declare module 'vitest' {
interface Assertion<T = any> extends jest.Matchers<void, T>, TestingLibraryMatchers<T, void> {}
}
// Extends Vitest's expect method with methods from react-testing-library
expect.extend(matchers);
// runs a cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
// Clears all mocks after every test
vi.clearAllMocks();
// runs a cleanup after each test case (e.g. clearing jsdom)
cleanup();
});
@ -18,5 +25,3 @@ afterEach(() => {
(global as any).scrollTo = () => {};
(global as any).prompt = () => {};
(global as any).matchMedia = (media: string) => ({ matches: false, media });
setAutoFreeze(false); // TODO Bypassing a bug on jest

84
package-lock.json generated
View file

@ -55,7 +55,7 @@
"@shlinkio/eslint-config-js-coding-standard": "~2.1.0",
"@shlinkio/stylelint-config-css-coding-standard": "~1.0.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@total-typescript/shoehorn": "^0.1.0",
"@types/json2csv": "^5.0.3",
@ -74,7 +74,6 @@
"adm-zip": "^0.5.10",
"chalk": "^5.2.0",
"eslint": "^8.30.0",
"identity-obj-proxy": "^3.0.0",
"jsdom": "^22.0.0",
"resize-observer-polyfill": "^1.5.1",
"sass": "^1.57.1",
@ -2695,21 +2694,22 @@
}
},
"node_modules/@testing-library/dom": {
"version": "8.13.0",
"version": "9.3.0",
"resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.0.tgz",
"integrity": "sha512-Dffe68pGwI6WlLRYR2I0piIkyole9cSBH5jGQKCGMRpHW5RHCqAUaqc2Kv0tUyd4dU4DLPKhJIjyKOnjv4tuUw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/code-frame": "^7.10.4",
"@babel/runtime": "^7.12.5",
"@types/aria-query": "^4.2.0",
"@types/aria-query": "^5.0.1",
"aria-query": "^5.0.0",
"chalk": "^4.1.0",
"dom-accessibility-api": "^0.5.9",
"lz-string": "^1.4.4",
"lz-string": "^1.5.0",
"pretty-format": "^27.0.2"
},
"engines": {
"node": ">=12"
"node": ">=14"
}
},
"node_modules/@testing-library/dom/node_modules/ansi-styles": {
@ -2865,16 +2865,17 @@
}
},
"node_modules/@testing-library/react": {
"version": "13.4.0",
"version": "14.0.0",
"resolved": "https://registry.npmjs.org/@testing-library/react/-/react-14.0.0.tgz",
"integrity": "sha512-S04gSNJbYE30TlIMLTzv6QCTzt9AqIF5y6s6SzVFILNcNvbV/jU96GeiTPillGQo+Ny64M/5PV7klNYYgv5Dfg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@testing-library/dom": "^8.5.0",
"@testing-library/dom": "^9.0.0",
"@types/react-dom": "^18.0.0"
},
"engines": {
"node": ">=12"
"node": ">=14"
},
"peerDependencies": {
"react": "^18.0.0",
@ -2908,9 +2909,10 @@
"dev": true
},
"node_modules/@types/aria-query": {
"version": "4.2.2",
"dev": true,
"license": "MIT"
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.1.tgz",
"integrity": "sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==",
"dev": true
},
"node_modules/@types/babel__core": {
"version": "7.1.20",
@ -5984,11 +5986,6 @@
"node": ">=6"
}
},
"node_modules/harmony-reflect": {
"version": "1.6.1",
"dev": true,
"license": "(Apache-2.0 OR MPL-1.1)"
},
"node_modules/has": {
"version": "1.0.3",
"license": "MIT",
@ -6162,17 +6159,6 @@
"version": "7.1.1",
"license": "ISC"
},
"node_modules/identity-obj-proxy": {
"version": "3.0.0",
"dev": true,
"license": "MIT",
"dependencies": {
"harmony-reflect": "^1.4.6"
},
"engines": {
"node": ">=4"
}
},
"node_modules/ignore": {
"version": "5.2.4",
"dev": true,
@ -7327,9 +7313,10 @@
}
},
"node_modules/lz-string": {
"version": "1.4.4",
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz",
"integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",
"dev": true,
"license": "WTFPL",
"bin": {
"lz-string": "bin/bin.js"
}
@ -12283,16 +12270,18 @@
}
},
"@testing-library/dom": {
"version": "8.13.0",
"version": "9.3.0",
"resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.0.tgz",
"integrity": "sha512-Dffe68pGwI6WlLRYR2I0piIkyole9cSBH5jGQKCGMRpHW5RHCqAUaqc2Kv0tUyd4dU4DLPKhJIjyKOnjv4tuUw==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.10.4",
"@babel/runtime": "^7.12.5",
"@types/aria-query": "^4.2.0",
"@types/aria-query": "^5.0.1",
"aria-query": "^5.0.0",
"chalk": "^4.1.0",
"dom-accessibility-api": "^0.5.9",
"lz-string": "^1.4.4",
"lz-string": "^1.5.0",
"pretty-format": "^27.0.2"
},
"dependencies": {
@ -12390,11 +12379,13 @@
}
},
"@testing-library/react": {
"version": "13.4.0",
"version": "14.0.0",
"resolved": "https://registry.npmjs.org/@testing-library/react/-/react-14.0.0.tgz",
"integrity": "sha512-S04gSNJbYE30TlIMLTzv6QCTzt9AqIF5y6s6SzVFILNcNvbV/jU96GeiTPillGQo+Ny64M/5PV7klNYYgv5Dfg==",
"dev": true,
"requires": {
"@babel/runtime": "^7.12.5",
"@testing-library/dom": "^8.5.0",
"@testing-library/dom": "^9.0.0",
"@types/react-dom": "^18.0.0"
}
},
@ -12414,7 +12405,9 @@
"dev": true
},
"@types/aria-query": {
"version": "4.2.2",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.1.tgz",
"integrity": "sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==",
"dev": true
},
"@types/babel__core": {
@ -14486,10 +14479,6 @@
"version": "2.1.0",
"dev": true
},
"harmony-reflect": {
"version": "1.6.1",
"dev": true
},
"has": {
"version": "1.0.3",
"requires": {
@ -14594,13 +14583,6 @@
"idb": {
"version": "7.1.1"
},
"identity-obj-proxy": {
"version": "3.0.0",
"dev": true,
"requires": {
"harmony-reflect": "^1.4.6"
}
},
"ignore": {
"version": "5.2.4",
"dev": true
@ -15321,7 +15303,9 @@
}
},
"lz-string": {
"version": "1.4.4",
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz",
"integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",
"dev": true
},
"magic-string": {

View file

@ -72,7 +72,7 @@
"@shlinkio/eslint-config-js-coding-standard": "~2.1.0",
"@shlinkio/stylelint-config-css-coding-standard": "~1.0.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@total-typescript/shoehorn": "^0.1.0",
"@types/json2csv": "^5.0.3",
@ -91,7 +91,6 @@
"adm-zip": "^0.5.10",
"chalk": "^5.2.0",
"eslint": "^8.30.0",
"identity-obj-proxy": "^3.0.0",
"jsdom": "^22.0.0",
"resize-observer-polyfill": "^1.5.1",
"sass": "^1.57.1",

View file

@ -17,8 +17,6 @@ describe('ShlinkApiClient', () => {
['abc123', 'example.com'],
];
beforeEach(vi.clearAllMocks);
describe('listShortUrls', () => {
const expectedList = ['foo', 'bar'];

View file

@ -32,8 +32,6 @@ describe('<App />', () => {
);
};
afterEach(vi.clearAllMocks);
it('renders children components', () => {
setUp();

View file

@ -7,8 +7,6 @@ describe('<AppUpdateBanner />', () => {
const forceUpdate = vi.fn();
const setUp = () => renderWithEvents(<AppUpdateBanner isOpen toggle={toggle} forceUpdate={forceUpdate} />);
afterEach(vi.clearAllMocks);
it('renders initial state', () => {
setUp();

View file

@ -18,7 +18,6 @@ describe('<ErrorHandler />', () => {
beforeEach(() => {
vi.spyOn(console, 'error').mockImplementation(() => {}); // Silence react errors
});
afterEach(vi.resetAllMocks);
it('renders children when no error has occurred', () => {
render(<ErrorHandler children={<span>Foo</span>} />);

View file

@ -44,8 +44,6 @@ describe('<MenuLayout />', () => {
(useParams as any).mockReturnValue({ serverId: 'abc123' });
});
afterEach(vi.clearAllMocks);
it('shows loading indicator while loading server', () => {
setUp(null);

View file

@ -4,8 +4,6 @@ describe('HttpClient', () => {
const fetch = vi.fn();
const httpClient = new HttpClient(fetch);
beforeEach(vi.clearAllMocks);
describe('fetchJson', () => {
it('throws json on success', async () => {
const theError = { error: true, foo: 'bar' };

View file

@ -7,7 +7,6 @@ describe('ReportExporter', () => {
const jsonToCsv = vi.fn();
let exporter: ReportExporter;
beforeEach(vi.clearAllMocks);
beforeEach(() => {
(global as any).Blob = class Blob {};
(global as any).URL = { createObjectURL: () => '' };

View file

@ -16,8 +16,6 @@ describe('<DomainSelector />', () => {
<DomainSelector value={value} domainsList={domainsList} listDomains={vi.fn()} onChange={vi.fn()} />,
);
afterEach(vi.clearAllMocks);
it.each([
['', 'Domain', 'domains-dropdown__toggle-btn'],
['my-domain.com', 'Domain: my-domain.com', 'domains-dropdown__toggle-btn--active'],

View file

@ -20,8 +20,6 @@ describe('<ManageDomains />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it('shows loading message while domains are loading', () => {
setUp(fromPartial({ loading: true, filteredDomains: [] }));

View file

@ -19,8 +19,6 @@ describe('<DomainDropdown />', () => {
</MemoryRouter>,
);
afterEach(vi.clearAllMocks);
it('renders expected menu items', () => {
setUp();

View file

@ -10,8 +10,6 @@ describe('<DomainStatusIcon />', () => {
<DomainStatusIcon status={status} matchMedia={matchMedia} />,
);
beforeEach(vi.clearAllMocks);
it.each([
['validating' as DomainStatus],
['invalid' as DomainStatus],

View file

@ -17,8 +17,6 @@ describe('<EditDomainRedirectsModal />', () => {
<EditDomainRedirectsModal domain={domain} isOpen toggle={toggle} editDomainRedirects={editDomainRedirects} />,
);
afterEach(vi.clearAllMocks);
it('renders domain in header', () => {
setUp();
expect(screen.getByRole('heading')).toHaveTextContent('Edit redirects for foo.com');

View file

@ -4,8 +4,6 @@ import type { ShlinkDomainRedirects } from '../../../src/api/types';
import { editDomainRedirects } from '../../../src/domains/reducers/domainRedirects';
describe('domainRedirectsReducer', () => {
beforeEach(vi.clearAllMocks);
describe('editDomainRedirects', () => {
const domain = 'example.com';
const redirects = fromPartial<ShlinkDomainRedirects>({});

View file

@ -30,8 +30,6 @@ describe('domainsListReducer', () => {
editDomainRedirectsThunk,
);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns loading on LIST_DOMAINS_START', () => {
expect(reducer(undefined, listDomainsAction.pending(''))).toEqual(

View file

@ -7,8 +7,6 @@ import type { MercureInfo } from '../../../src/mercure/reducers/mercureInfo';
vi.mock('event-source-polyfill');
describe('helpers', () => {
afterEach(vi.resetAllMocks);
describe('bindToMercureTopic', () => {
const onMessage = vi.fn();
const onTokenExpired = vi.fn();

View file

@ -12,8 +12,6 @@ describe('mercureInfoReducer', () => {
const buildShlinkApiClient = () => fromPartial<ShlinkApiClient>({ mercureInfo: getMercureInfo });
const { loadMercureInfo, reducer } = mercureInfoReducerCreator(buildShlinkApiClient);
beforeEach(vi.resetAllMocks);
describe('reducer', () => {
it('returns loading on GET_MERCURE_INFO_START', () => {
expect(reducer(undefined, loadMercureInfo.pending(''))).toEqual({

View file

@ -28,8 +28,6 @@ describe('<CreateServer />', () => {
return renderWithEvents(<CreateServer createServers={createServersMock} servers={servers} />);
};
beforeEach(vi.clearAllMocks);
it('shows success message when imported is true', () => {
setUp(true);

View file

@ -30,8 +30,6 @@ describe('<DeleteServerModal />', () => {
);
};
afterEach(vi.clearAllMocks);
it('renders a modal window', () => {
setUp();

View file

@ -31,8 +31,6 @@ describe('<EditServer />', () => {
(useNavigate as any).mockReturnValue(navigate);
});
afterEach(vi.clearAllMocks);
it('renders nothing if selected server is not reachable', () => {
setUp(fromPartial<SelectedServer>({}));

View file

@ -23,8 +23,6 @@ describe('<ManageServers />', () => {
<MemoryRouter><ManageServers servers={servers} /></MemoryRouter>,
);
afterEach(vi.clearAllMocks);
it('shows search field which allows searching servers, affecting te amount of rendered rows', async () => {
const { user } = setUp({
foo: createServerMock('foo'),

View file

@ -19,8 +19,6 @@ describe('<ManageServersRowDropdown />', () => {
);
};
afterEach(vi.clearAllMocks);
it('renders expected amount of dropdown items', async () => {
const { user } = setUp();

View file

@ -12,8 +12,6 @@ describe('<DuplicatedServersModal />', () => {
);
const mockServer = (data: Partial<ServerData> = {}) => fromPartial<ServerData>(data);
beforeEach(vi.clearAllMocks);
it.each([
[[], 0],
[[mockServer()], 2],

View file

@ -24,8 +24,6 @@ describe('<ImportServersBtn />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it('shows tooltip on button hover', async () => {
const { user } = setUp();

View file

@ -5,8 +5,6 @@ describe('<ServerForm />', () => {
const onSubmit = vi.fn();
const setUp = () => render(<ServerForm onSubmit={onSubmit}>Something</ServerForm>);
afterEach(vi.resetAllMocks);
it('renders components', () => {
setUp();

View file

@ -3,8 +3,6 @@ import type { HttpClient } from '../../../src/common/services/HttpClient';
import { fetchServers } from '../../../src/servers/reducers/remoteServers';
describe('remoteServersReducer', () => {
afterEach(vi.clearAllMocks);
describe('fetchServers', () => {
const dispatch = vi.fn();
const fetchJson = vi.fn();

View file

@ -19,8 +19,6 @@ describe('selectedServerReducer', () => {
const selectServer = selectServerCreator(buildApiClient);
const { reducer } = selectedServerReducerCreator(selectServer);
afterEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns default when action is RESET_SELECTED_SERVER', () =>
expect(reducer(null, resetSelectedServer())).toBeNull());

View file

@ -15,8 +15,6 @@ describe('serversReducer', () => {
def456: fromPartial({ id: 'def456' }),
};
afterEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns edited server when action is EDIT_SERVER', () =>
expect(serversReducer(list, editServer('abc123', { name: 'foo' }))).toEqual({

View file

@ -23,8 +23,6 @@ describe('ServersExporter', () => {
});
const createCsvjsonMock = (throwError = false) => (throwError ? erroneousToCsv : vi.fn(() => ''));
beforeEach(vi.clearAllMocks);
describe('exportServers', () => {
let originalConsole: Console;
const error = vi.fn();

View file

@ -14,8 +14,6 @@ describe('ServersImporter', () => {
});
const importer = new ServersImporter(csvjsonMock, () => fileReaderMock);
beforeEach(vi.clearAllMocks);
describe('importServersFromFile', () => {
it('rejects with error if no file was provided', async () => {
await expect(importer.importServersFromFile()).rejects.toEqual(

View file

@ -17,8 +17,6 @@ describe('<RealTimeUpdatesSettings />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it('renders enabled real time updates as expected', () => {
setUp({ enabled: true });

View file

@ -13,8 +13,6 @@ describe('<ShortUrlCreationSettings />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it.each([
[{ validateUrls: true }, true],
[{ validateUrls: false }, false],

View file

@ -11,8 +11,6 @@ describe('<ShortUrlsListSettings />', () => {
<ShortUrlsListSettings settings={fromPartial({ shortUrlsList })} setShortUrlsListSettings={setSettings} />,
);
afterEach(vi.clearAllMocks);
it.each([
[undefined, 'Order by: Created at - DESC'],
[{}, 'Order by: Created at - DESC'],

View file

@ -11,8 +11,6 @@ describe('<TagsSettings />', () => {
<TagsSettings settings={fromPartial({ tags })} setTagsSettings={setTagsSettings} />,
);
afterEach(vi.clearAllMocks);
it('renders expected amount of groups', () => {
setUp();

View file

@ -11,8 +11,6 @@ describe('<UserInterfaceSettings />', () => {
<UserInterfaceSettings settings={fromPartial({ ui })} setUiSettings={setUiSettings} />,
);
afterEach(vi.clearAllMocks);
it.each([
[{ theme: 'dark' as Theme }, true],
[{ theme: 'light' as Theme }, false],

View file

@ -10,8 +10,6 @@ describe('<VisitsSettings />', () => {
<VisitsSettings settings={fromPartial(settings)} setVisitsSettings={setVisitsSettings} />,
);
afterEach(vi.clearAllMocks);
it('renders expected components', () => {
setUp();

View file

@ -23,8 +23,6 @@ describe('<ShortUrlForm />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it.each([
[
async (user: UserEvent) => {

View file

@ -36,8 +36,6 @@ describe('<ShortUrlsFilteringBar />', () => {
);
};
afterEach(vi.clearAllMocks);
it('renders expected children components', () => {
setUp();

View file

@ -51,8 +51,6 @@ describe('<ShortUrlsList />', () => {
(useNavigate as any).mockReturnValue(navigate);
});
afterEach(vi.clearAllMocks);
it('wraps expected components', () => {
setUp();

View file

@ -15,8 +15,6 @@ describe('<ShortUrlsTable />', () => {
<ShortUrlsTable shortUrlsList={shortUrlsList} selectedServer={server} orderByColumn={() => orderByColumn} />,
);
afterEach(vi.resetAllMocks);
it('should render inner table by default', () => {
setUp();
expect(screen.getByRole('table')).toBeInTheDocument();

View file

@ -13,8 +13,6 @@ describe('<CreateShortUrlResult />', () => {
<CreateShortUrlResult resetCreateShortUrl={() => {}} creation={creation} />,
);
afterEach(vi.clearAllMocks);
it('renders an error when error is true', () => {
setUp({ error: true, saved: false, saving: false });
expect(screen.getByText('An error occurred while creating the URL :(')).toBeInTheDocument();

View file

@ -31,8 +31,6 @@ describe('<DeleteShortUrlModal />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it('shows generic error when non-threshold error occurs', () => {
setUp({
loading: false,

View file

@ -19,8 +19,6 @@ describe('<ExportShortUrlsBtn />', () => {
</MemoryRouter>,
);
afterEach(vi.clearAllMocks);
it.each([
[undefined, '0'],
[1, '1'],

View file

@ -17,8 +17,6 @@ describe('<QrCodeModal />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it('shows an external link to the URL in the header', () => {
setUp();
const externalLink = screen.getByRole('heading').querySelector('a');

View file

@ -10,8 +10,6 @@ describe('<QrErrorCorrectionDropdown />', () => {
<QrErrorCorrectionDropdown errorCorrection={initialErrorCorrection} setErrorCorrection={setErrorCorrection} />,
);
afterEach(vi.clearAllMocks);
it('renders initial state', async () => {
const { user } = setUp();
const btn = screen.getByRole('button');

View file

@ -8,8 +8,6 @@ describe('<QrFormatDropdown />', () => {
const setFormat = vi.fn();
const setUp = () => renderWithEvents(<QrFormatDropdown format={initialFormat} setFormat={setFormat} />);
afterEach(vi.clearAllMocks);
it('renders initial state', async () => {
const { user } = setUp();
const btn = screen.getByRole('button');

View file

@ -14,8 +14,6 @@ describe('shortUrlCreationReducer', () => {
const createShortUrl = createShortUrlCreator(buildShlinkApiClient);
const { reducer, resetCreateShortUrl } = shortUrlCreationReducerCreator(createShortUrl);
afterEach(vi.resetAllMocks);
describe('reducer', () => {
it('returns loading on CREATE_SHORT_URL_START', () => {
expect(reducer(undefined, createShortUrl.pending('', fromPartial({})))).toEqual({

View file

@ -12,8 +12,6 @@ describe('shortUrlDeletionReducer', () => {
const deleteShortUrl = deleteShortUrlCreator(buildShlinkApiClient);
const { reducer, resetDeleteShortUrl } = shortUrlDeletionReducerCreator(deleteShortUrl);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns loading on DELETE_SHORT_URL_START', () =>
expect(reducer(undefined, deleteShortUrl.pending('', { shortCode: '' }))).toEqual({

View file

@ -10,8 +10,6 @@ describe('shortUrlDetailReducer', () => {
const buildShlinkApiClient = () => fromPartial<ShlinkApiClient>({ getShortUrl: getShortUrlCall });
const { reducer, getShortUrlDetail } = shortUrlDetailReducerCreator(buildShlinkApiClient);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns loading on GET_SHORT_URL_DETAIL_START', () => {
const { loading } = reducer({ loading: false, error: false }, getShortUrlDetail.pending('', { shortCode: '' }));

View file

@ -16,8 +16,6 @@ describe('shortUrlEditionReducer', () => {
const editShortUrl = editShortUrlCreator(buildShlinkApiClient);
const { reducer } = shortUrlEditionReducerCreator(editShortUrl);
afterEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns loading on EDIT_SHORT_URL_START', () => {
expect(reducer(undefined, editShortUrl.pending('', fromPartial({})))).toEqual({
@ -51,8 +49,6 @@ describe('shortUrlEditionReducer', () => {
selectedServer,
});
afterEach(vi.clearAllMocks);
it.each([[undefined], [null], ['example.com']])('dispatches short URL on success', async (domain) => {
await editShortUrl({ shortCode, domain, data: { longUrl } })(dispatch, createGetState(), {});

View file

@ -21,8 +21,6 @@ describe('shortUrlsListReducer', () => {
const createShortUrl = createShortUrlCreator(buildShlinkApiClient);
const { reducer } = shortUrlsListReducerCreator(listShortUrls, editShortUrl, createShortUrl);
afterEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns loading on LIST_SHORT_URLS_START', () =>
expect(reducer(undefined, listShortUrls.pending(''))).toEqual({

View file

@ -21,8 +21,6 @@ describe('<TagsList />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it('shows a loading message when tags are being loaded', () => {
setUp({ loading: true });

View file

@ -26,7 +26,9 @@ describe('<TagsTable />', () => {
);
};
afterEach(vi.clearAllMocks);
afterEach(() => {
vi.clearAllMocks();
});
it('renders empty result if there are no tags', () => {
setUp();

View file

@ -18,8 +18,6 @@ describe('<DeleteTagConfirmModal />', () => {
/>,
);
afterEach(vi.resetAllMocks);
it('asks confirmation for provided tag to be deleted', () => {
setUp({ error: false, deleted: false, deleting: false });

View file

@ -15,8 +15,6 @@ describe('<EditTagModal />', () => {
);
};
afterEach(vi.clearAllMocks);
it('allows modal to be toggled with different mechanisms', async () => {
const { user } = setUp();

View file

@ -31,8 +31,6 @@ describe('<Tag />', () => {
</Tag>,
);
afterEach(vi.clearAllMocks);
it.each([
[true],
[false],

View file

@ -20,8 +20,6 @@ describe('<TagsSelector />', () => {
/>,
);
afterEach(vi.clearAllMocks);
it('has an input for tags', () => {
setUp();
expect(screen.getByPlaceholderText('Add tags to the URL')).toBeInTheDocument();

View file

@ -8,8 +8,6 @@ describe('tagDeleteReducer', () => {
const buildShlinkApiClient = () => fromPartial<ShlinkApiClient>({ deleteTags: deleteTagsCall });
const { reducer, deleteTag } = tagDeleteReducerCreator(buildShlinkApiClient);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns loading on DELETE_TAG_START', () => {
expect(reducer(undefined, deleteTag.pending('', ''))).toEqual({

View file

@ -53,8 +53,6 @@ describe('tagEditReducer', () => {
const dispatch = vi.fn();
const getState = () => fromPartial<ShlinkState>({});
afterEach(vi.clearAllMocks);
it('calls API on success', async () => {
editTagCall.mockResolvedValue(undefined);

View file

@ -21,8 +21,6 @@ describe('tagsListReducer', () => {
const createShortUrl = createShortUrlCreator(buildShlinkApiClient);
const { reducer } = tagsListReducerCreator(listTags, createShortUrl);
afterEach(vi.clearAllMocks);
describe('reducer', () => {
it('returns loading on LIST_TAGS_START', () => {
expect(reducer(undefined, listTags.pending(''))).toEqual(expect.objectContaining({

View file

@ -5,8 +5,6 @@ describe('<CopyToClipboardIcon />', () => {
const onCopy = vi.fn();
const setUp = (text = 'foo') => renderWithEvents(<CopyToClipboardIcon text={text} onCopy={onCopy} />);
afterEach(vi.clearAllMocks);
it('wraps expected components', () => {
const { container } = setUp();
expect(container).toMatchSnapshot();

View file

@ -13,8 +13,6 @@ describe('<PaginationDropdown />', () => {
return result;
};
afterEach(vi.clearAllMocks);
it('renders expected amount of items', async () => {
await setUp();
expect(screen.getAllByRole('menuitem')).toHaveLength(5);

View file

@ -20,8 +20,6 @@ describe('<DateIntervalDropdownItems />', () => {
return { user, ...renderResult };
};
afterEach(vi.clearAllMocks);
it('renders expected amount of items', async () => {
await setUp();

View file

@ -9,8 +9,6 @@ describe('<DateRangeRow />', () => {
<DateRangeRow onEndDateChange={onEndDateChange} onStartDateChange={onStartDateChange} />,
);
afterEach(vi.clearAllMocks);
it('renders two date inputs', () => {
setUp();
expect(screen.getAllByRole('textbox')).toHaveLength(2);

View file

@ -22,8 +22,6 @@ describe('<DateRangeSelector />', () => {
return result;
};
afterEach(vi.clearAllMocks);
it('renders proper amount of items', async () => {
const { container } = await setUp();

View file

@ -28,8 +28,6 @@ describe('<VisitsTable />', () => {
],
});
afterEach(vi.resetAllMocks);
it('renders expected amount of columns', () => {
setUp([], []);
expect(screen.getAllByRole('columnheader')).toHaveLength(8);

View file

@ -13,8 +13,6 @@ describe('<VisitsFilterDropdown />', () => {
/>,
);
beforeEach(vi.clearAllMocks);
it('has expected text', () => {
setUp();
expect(screen.getByRole('button', { name: 'Filters' })).toBeInTheDocument();

View file

@ -26,8 +26,6 @@ describe('domainVisitsReducer', () => {
const getDomainVisits = getDomainVisitsCreator(buildApiClientMock);
const { reducer, cancelGetVisits: cancelGetDomainVisits } = domainVisitsReducerCreator(getDomainVisits);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
const buildState = (data: Partial<DomainVisits>) => fromPartial<DomainVisits>(data);

View file

@ -22,8 +22,6 @@ describe('nonOrphanVisitsReducer', () => {
const getNonOrphanVisits = getNonOrphanVisitsCreator(buildShlinkApiClient);
const { reducer, cancelGetVisits: cancelGetNonOrphanVisits } = nonOrphanVisitsReducerCreator(getNonOrphanVisits);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
const buildState = (data: Partial<VisitsInfo>) => fromPartial<VisitsInfo>(data);
@ -124,8 +122,6 @@ describe('nonOrphanVisitsReducer', () => {
orphanVisits: { cancelLoad: false },
});
beforeEach(vi.resetAllMocks);
it.each([
[undefined],
[{}],

View file

@ -22,8 +22,6 @@ describe('orphanVisitsReducer', () => {
const getOrphanVisits = getOrphanVisitsCreator(buildShlinkApiClientMock);
const { reducer, cancelGetVisits: cancelGetOrphanVisits } = orphanVisitsReducerCreator(getOrphanVisits);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
const buildState = (data: Partial<VisitsInfo>) => fromPartial<VisitsInfo>(data);

View file

@ -23,8 +23,6 @@ describe('shortUrlVisitsReducer', () => {
const getShortUrlVisits = getShortUrlVisitsCreator(buildApiClientMock);
const { reducer, cancelGetVisits: cancelGetShortUrlVisits } = shortUrlVisitsReducerCreator(getShortUrlVisits);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
const buildState = (data: Partial<ShortUrlVisits>) => fromPartial<ShortUrlVisits>(data);

View file

@ -23,8 +23,6 @@ describe('tagVisitsReducer', () => {
const getTagVisits = getTagVisitsCreator(buildShlinkApiClientMock);
const { reducer, cancelGetVisits: cancelGetTagVisits } = tagVisitsReducerCreator(getTagVisits);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
const buildState = (data: Partial<TagVisits>) => fromPartial<TagVisits>(data);

View file

@ -19,8 +19,6 @@ describe('visitsOverviewReducer', () => {
const loadVisitsOverview = loadVisitsOverviewCreator(buildApiClientMock);
const { reducer } = visitsOverviewReducerCreator(loadVisitsOverview);
beforeEach(vi.clearAllMocks);
describe('reducer', () => {
const state = (payload: Partial<VisitsOverview> = {}) => fromPartial<VisitsOverview>(payload);

View file

@ -41,10 +41,10 @@ export default defineConfig({
],
// Required code coverage. Lower than this will make the check fail
statements: 90,
branches: 80,
functions: 85,
lines: 90,
statements: 95,
branches: 90,
functions: 90,
lines: 95,
},
deps: {
inline: ['vitest-canvas-mock'],