Test that async functions reject correctly:
test('rejects for invalid user', async () => {
await expect(fetchUser(-1)).rejects.toThrow('Invalid ID');
});
// Or with try/catch
test('rejects for invalid user', async () => {
try {
await fetchUser(-1);
fail('Should have thrown');
} catch (e) {
expect(e.message).toBe('Invalid ID');
}
});