Jest
Mocking fetch in tests
global.fetch = jest.fn(() => Promise.resolve({ ok: true, json: () => Promise.resolve({ id: 1, name: 'Test' }) }));test('fetches user', async () => { const res = await fetch('/api/user'); const user = await res.json(); expect(user.name).toBe('Test');});