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

Unlock the full answer

Get the complete model answer, key points, common pitfalls, and access to 9+ more Full-Stack Developer interview questions.

Upgrade to Pro

Starting at $19/month • Cancel anytime