Quiz
Async Stubs and Test Timing Pitfalls
Understanding how to correctly stub async functions and assert on their resolved values in Node tests.
In a Node test using Sinon and Mocha, you stub a repository method that returns a Promise: `sinon.stub(repo, 'findUser').returns(Promise.resolve({ id: 1 }))`. Your test then calls the service under test and asserts on the result, but the assertion runs before the resolved value is available. Which fix most reliably addresses the root cause?