Mock entire modules to control their behavior:
jest.mock('./api');
import { fetchUser } from './api';
fetchUser.mockResolvedValue({ name: 'Test User' });
test('uses mocked API', async () => {
const user = await fetchUser(1);
expect(user.name).toBe('Test User');
});
The real module never runs. Your test controls all responses.