I\'m trying to mock out a method which takes a long time for testing purposes but can\'t find a good way to do this in Javascript. Any good approaches besides writing a very
If you can use the newer await/await syntax:
function sleep (time) { return new Promise((resolve) => setTimeout(resolve, time)); } async function example() { await sleep(4000); return 1; } console.log(await example());