Writing Unit Tests with Jest
What testing pattern is demonstrated for error scenarios?
test('handles API error', async () => {
const consoleSpy = jest.spyOn(console, 'error');
await expect(fetchData()).rejects.toThrow();
expect(consoleSpy).toHaveBeenCalled();
consoleSpy.mockRestore();
});