Question 7 of 10Pro Only
How do you test asynchronous code in Jest? Show different approaches for Promises and async/await.
Sample answer preview
## Testing Async Code in Jest ### 1. Async/Await (Recommended) ```javascript // Function to test async function fetchUser(id) { const response = await fetch(`/api/users/${id}`); return response.json(); } // Test with async/await test('fetchUser returns user data', async () => {…
async/awaitPromisesresolvesrejectsdone callbackwaitFor