refactor(web/test): default svelte-query mock in vitest.setup; remove from 34 files (B3)

This commit is contained in:
2026-05-08 11:08:41 -04:00
parent 923b8286ee
commit 3e34f1f7b3
35 changed files with 12 additions and 192 deletions
+12 -1
View File
@@ -1,9 +1,20 @@
import '@testing-library/jest-dom/vitest';
import { beforeEach, afterEach } from 'vitest';
import { beforeEach, afterEach, vi } from 'vitest';
import { render } from '@testing-library/svelte';
import ToastHost from './src/lib/components/ToastHost.svelte';
import { clearToast } from './src/lib/stores/toast.svelte';
// Default svelte-query mock for the whole test suite. Most component
// tests just need useQueryClient to return SOMETHING — they never assert
// on the result. Tests that need to assert on invalidateQueries (named
// mock pattern) override this with their own per-file vi.mock. The
// override wins because per-file mocks take precedence over setup-file
// mocks in vitest.
vi.mock('@tanstack/svelte-query', async (orig) => {
const actual = (await orig()) as Record<string, unknown>;
return { ...actual, useQueryClient: () => ({ invalidateQueries: vi.fn() }) };
});
// Node 25 ships a partial localStorage global that lacks getItem/setItem/clear
// unless launched with --localstorage-file. jsdom sees Node's global and skips
// installing its own. Replace with an in-memory Storage-compatible polyfill so