Unexpected result while running a unit test for the function containing setTimeout()

You can mock setTimeout and you can spy on console.log. You don't need to use async/await here, your defer() function doesn't use promises.