javascript - 已超出 Jest Call 重试次数

标签 javascript unit-testing jestjs babeljs

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

相关文章:

c# - 我如何使用 xUnit Assert.RaisesAny?

redis - 如何用 jest 模拟 Nestjs-redis

java - 使用外部 JS 文件更改 Servlet 的 HTML 输出

javascript - 防止 Phonegap notification.navigator 弹出窗口因对话框外的触摸而关闭

javascript - 使用 node.js 和 ldapjs 的 LDAP 绑定(bind)错误

javascript - 语法错误: Unexpected token >

javascript - 如何在 Angular 2 或 4 的 Jasmine 测试中模拟鼠标事件

java - 使用 TestNG 让每个测试方法在其自己的测试类实例中运行?

unit-testing - Jest 无法转换 node_modules

react-native - ReactNative 0.48 上的开 Jest 错误 "Cannot read property ' validAttributes' of undefined"