【发布时间】:2019-06-24 10:55:40
【问题描述】:
我正在尝试使用 setTimeout 进行简单的 async/await 测试,但运行时没有任何反应:
const testing = async () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('result');
}, 500);
});
}
jest.useFakeTimers()
it('tests async await', async () => {
const r = await testing();
expect(r).toBe('result');
jest.runAllTimers();
});
我可以像在 Jasmine 中那样使用真正的 setTimeout,但在 Jest 中您似乎必须使用假的。所以我确实包含了jest.useFakeTimers() 和jest.runAllTimers(),但这并没有解决它。
测试卡住了,永远无法完成。知道可能是什么问题吗?
【问题讨论】:
标签: timer async-await jestjs settimeout