import { cleanup } from '@testing-library/react'; import { afterEach } from 'vitest'; import '@testing-library/jest-dom/vitest'; // vitest.config.ts intentionally leaves `test.globals` off (test files import // describe/it/expect explicitly), so Testing Library's own auto-cleanup - // which only registers itself when it detects a *global* `afterEach` - never // fires on its own. Without this, unmounted DOM from one `it()` block leaks // into the next within the same file, and every query starts matching // duplicate nodes. afterEach(() => { cleanup(); });