Mocking Modules and Fetch
Mock external modules, fetch calls, and SvelteKit modules in unit tests.
Why Mock
Tests should isolate the unit under test. Mock external modules to avoid network calls and flaky tests.
vi.mock
Vitest provides vi.mock to replace modules.
vi.mock("$lib/api", () => ({ getUser: () => ({ name: "Mock" }) }));