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,8 +1,8 @@
import { screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { createMemoryHistory } from 'history';
import type { ReactNode } from 'react';
import { Router } from 'react-router';
import { page } from 'vitest/browser';
import { DeleteServerButton } from '../../src/servers/DeleteServerButton';
import { checkAccessibility } from '../__helpers__/accessibility';
import { renderWithStore } from '../__helpers__/setUpTest';
@@ -21,8 +21,9 @@ describe('<DeleteServerButton />', () => {
it('passes a11y checks', () => checkAccessibility(setUp('Delete me')));
it.each([['Foo bar'], ['baz'], ['something']])('renders expected content', (children) => {
it.each([['Foo bar'], ['baz'], ['something']])('renders expected content', async (children) => {
const { container } = setUp(children);
expect(container.firstChild).toBeTruthy();
expect(container.firstChild).toMatchSnapshot();
});
@@ -30,19 +31,19 @@ describe('<DeleteServerButton />', () => {
it('displays modal when button is clicked', async () => {
const { user } = setUp();
expect(screen.queryByText(/Are you sure you want to remove/)).not.toBeInTheDocument();
await user.click(screen.getByText('Remove this server'));
expect(screen.getByText(/Are you sure you want to remove/)).toBeInTheDocument();
await expect.element(page.getByText(/Are you sure you want to remove/)).not.toBeInTheDocument();
await user.click(page.getByText('Remove this server'));
await expect.element(page.getByText(/Are you sure you want to remove/)).toBeInTheDocument();
});
it('navigates to home when deletion is confirmed', async () => {
const { user, history } = setUp();
// Open modal
await user.click(screen.getByText('Remove this server'));
await user.click(page.getByText('Remove this server'));
expect(history.location.pathname).toEqual('/foo');
await user.click(screen.getByRole('button', { name: 'Delete' }));
await user.click(page.getByRole('button', { name: 'Delete' }));
expect(history.location.pathname).toEqual('/');
});
});