@testing-library/svelte with vitest does not auto-cleanup between tests in jsdom environment, causing 'Found multiple elements' errors when running multiple component tests in the same file
Add explicit cleanup to your vitest setup file. Auto-cleanup does not reliably trigger in vitest's jsdom environment with @testing-library/svelte:
// src/test-setup.ts
import '@testing-library/jest-dom/vitest';
import { cleanup } from '@testing-library/svelte';
import { afterEach } from 'vitest';
afterEach(() => {
cleanup();
});