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 <noreply@anthropic.com>
This commit is contained in:
36
vitest-setup-client.ts
Normal file
36
vitest-setup-client.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/// <reference types="@vitest/browser/matchers" />
|
||||||
|
/// <reference types="@vitest/browser/providers/playwright" />
|
||||||
|
|
||||||
|
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
|
||||||
|
}));
|
||||||
Reference in New Issue
Block a user