我在以下测试中有错误。我的节点版本是:v12.10.0。有没有 setTimeout 的替代品?
test('demo code', async () => {
const cc = await projectSetup(project);
const onNotification = jest.fn();
cc.sendNotification();
await waitForExpect(() => {
expect(onNotification).toHaveBeenCalledTimes(2);
});
});
错误日志如下
Call retries were exceeded
at ChildProcessWorker.initialize (../../../node_modules/jest-worker/build/workers/ChildProcessWorker.js:230:21)
最佳答案
只需添加 jest.useFakeTimers();
在你的进口之后
...
jest.useFakeTimers();
test('demo code', async () => {
const cc = await projectSetup(project);
const onNotification = jest.fn();
cc.sendNotification();
await waitForExpect(() => {
expect(onNotification).toHaveBeenCalledTimes(2);
});
});
它适用于我的代码
关于javascript - 已超出 Jest Call 重试次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60817275/