I have this function:
function sleep(milliseconds) {
return new Promise((resolve) => {
setTimeout(resolve, milliseconds);
});
}
Basically this function delays logic, e.g.:
function sleep(milliseconds) {
return new Promise((resolve) => {
setTimeout(resolve, milliseconds);
});
}
async function delayedGreeting() {
console.log("Hello");
await sleep(2000); //will wait 2 Seconds and after that will display the next code
console.log("World!");
}
delayedGreeting();
I want to test the sleep
function using Jest.
test('test', async () => {
await sleep(2000);
});
I don't know how to test this function.