- 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>
37 lines
851 B
TypeScript
37 lines
851 B
TypeScript
/// <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
|
|
}));
|