From b0e8e4c0b9cd4d4f8d67da6b199dc91ecc9694f4 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 3 Feb 2026 23:28:49 +0100 Subject: [PATCH] feat(09-01): add SvelteKit module mocks for browser tests - Mock $app/navigation (goto, invalidate, invalidateAll, beforeNavigate, afterNavigate) - Mock $app/stores (page, navigating, updated) - Mock $app/environment (browser, dev, building) - Add Vitest browser type references Co-Authored-By: Claude Opus 4.5 --- vitest-setup-client.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 vitest-setup-client.ts diff --git a/vitest-setup-client.ts b/vitest-setup-client.ts new file mode 100644 index 0000000..3872b7a --- /dev/null +++ b/vitest-setup-client.ts @@ -0,0 +1,36 @@ +/// +/// + +import { vi } from 'vitest'; +import { writable } from 'svelte/store'; + +// Mock $app/navigation +vi.mock('$app/navigation', () => ({ + goto: vi.fn(() => Promise.resolve()), + invalidate: vi.fn(() => Promise.resolve()), + invalidateAll: vi.fn(() => Promise.resolve()), + beforeNavigate: vi.fn(), + afterNavigate: vi.fn() +})); + +// Mock $app/stores +vi.mock('$app/stores', () => ({ + page: writable({ + url: new URL('http://localhost'), + params: {}, + route: { id: null }, + status: 200, + error: null, + data: {}, + form: null + }), + navigating: writable(null), + updated: { check: vi.fn(), subscribe: writable(false).subscribe } +})); + +// Mock $app/environment +vi.mock('$app/environment', () => ({ + browser: true, + dev: true, + building: false +}));