Mocking — fake API responses.
1import { describe, it, expect, vi } from "vitest"2import { mount } from "@vue/test-utils"3import UserProfile from "./UserProfile.vue"45describe("UserProfile", () => {6 it("loads user data", async () => {7 // Mock fetch8 vi.spyOn(global, "fetch").mockResolvedValue({9 json: () => Promise.resolve({ name: "John" })10 })1112 const wrapper = mount(UserProfile, {13 props: { userId: 1 }14 })1516 await wrapper.vm.$nextTick()1718 expect(wrapper.text()).toContain("John")19 expect(fetch).toHaveBeenCalledWith("/api/users/1")20 })21})