Replace @testing-library/jest-dom with built-in vitest browser assertions

This commit is contained in:
Alejandro Celaya
2026-08-16 19:32:41 +02:00
parent ba73644871
commit 585d7c6f63
30 changed files with 305 additions and 429 deletions

View File

@@ -1,10 +1,10 @@
import type { HttpClient } from '@shlinkio/shlink-js-sdk';
import { act, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { act } from 'react';
import { MemoryRouter } from 'react-router';
import { page } from 'vitest/browser';
import { App } from '../../src/app/App';
import { ContainerProvider } from '../../src/container/context';
import type { ServerWithId } from '../../src/servers/data';
import { checkAccessibility } from '../__helpers__/accessibility';
import { renderWithStore } from '../__helpers__/setUpTest';
@@ -30,8 +30,8 @@ describe('<App />', () => {
{
initialState: {
servers: {
abc123: fromPartial<ServerWithId>({ id: 'abc123', name: 'abc123 server' }),
def456: fromPartial<ServerWithId>({ id: 'def456', name: 'def456 server' }),
abc123: fromPartial({ id: 'abc123', name: 'abc123 server' }),
def456: fromPartial({ id: 'def456', name: 'def456 server' }),
},
settings: fromPartial({}),
appUpdated: false,
@@ -54,7 +54,7 @@ describe('<App />', () => {
['/other', 'Oops! We could not find requested route.'],
])('renders expected route', async (activeRoute, expectedComponent) => {
await setUp(activeRoute);
expect(screen.getByText(expectedComponent)).toBeInTheDocument();
await expect.element(page.getByText(expectedComponent)).toBeInTheDocument();
});
it.each([
@@ -63,12 +63,12 @@ describe('<App />', () => {
['/', true],
])('renders expected classes on shlink-wrapper based on current pathname', async (pathname, isFlex) => {
await setUp(pathname);
const shlinkWrapper = screen.getByTestId('shlink-wrapper');
const shlinkWrapper = page.getByTestId('shlink-wrapper');
if (isFlex) {
expect(shlinkWrapper).toHaveClass('flex');
await expect.element(shlinkWrapper).toHaveClass('flex');
} else {
expect(shlinkWrapper).not.toHaveClass('flex');
await expect.element(shlinkWrapper).not.toHaveClass('flex');
}
});
});