Question · Vue.js course · Module 12: Testing & Deploy
Mocking fetch in tests
How do you mock the global fetch in Vitest?
Answer options
- By importing real fetch from node-fetch
- global.fetch = vi.fn().mockResolvedValue({ json: async () => data })
- Vitest automatically mocks all HTTP requests
- You cannot mock fetch - you must use a real API
You can check the correct answer by solving this task in the CodeWorlds game.