gpt4 book ai didi

javascript - 已超出 Jest Call 重试次数

转载 作者:行者123 更新时间:2023-12-04 11:03:07 24 4
gpt4 key购买 nike

我在以下测试中有错误。我的节点版本是: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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com