Jest setTimeout not pausing test
A nice and clean way to do it (without callbacks) we can simply run an await
and pass the res
to setTimeout(res, XXX)
like so:
it('works with await Promise and setTimeout', async () => {
// await 15000ms before continuing further
await new Promise(res => setTimeout(res, 15000));
// run your test
expect(true).toBe(true)
});
it('has working hooks', async () => {
await new Promise(res => setTimeout(() => {
console.log("Why don't I run?")
expect(true).toBe(true)
res()
}, 15000))
})
or
it('has working hooks', done => {
setTimeout(() => {
console.log("Why don't I run?")
expect(true).toBe(true)
done()
}, 15000)
})