it('has working hooks', async () => {
setTimeout(() => {
console.log("Why don't I run?")
expect(true).toBe(true)
}, 15000)
我已经查看了这个答案、Jest 文档和几个 GitHub 线程:
此时,超时内的函数没有运行。 我怎样才能让 Jest 暂停执行测试 15 秒,然后运行内部函数?
谢谢!
最佳答案
it('has working hooks', async () => {
await new Promise(res => setTimeout(() => {
console.log("Why don't I run?")
expect(true).toBe(true)
res()
}, 15000))
})
或
it('has working hooks', done => {
setTimeout(() => {
console.log("Why don't I run?")
expect(true).toBe(true)
done()
}, 15000)
})
关于javascript - Jest setTimeout 不暂停测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46077176/