'Jest Call retries were exceeded

I have error in the following below test. My node version is : v12.10.0. is there any alternative of setTimeout?

   test('demo code', async () => {
        const cc = await projectSetup(project);
        const onNotification = jest.fn();
        cc.sendNotification();
        await waitForExpect(() => {
            expect(onNotification).toHaveBeenCalledTimes(2);
        });

    });

The Error log is as

Call retries were exceeded

  at ChildProcessWorker.initialize (../../../node_modules/jest-worker/build/workers/ChildProcessWorker.js:230:21)


Solution 1:[1]

just add jest.useFakeTimers(); after your imports

...
jest.useFakeTimers();

test('demo code', async () => {
        const cc = await projectSetup(project);
        const onNotification = jest.fn();
        cc.sendNotification();
        await waitForExpect(() => {
            expect(onNotification).toHaveBeenCalledTimes(2);
        });

    });

it works in my code

Solution 2:[2]

In my case, the actual problem was with the promise handling. I got the same issue when I was running all my test cases in one go with the jest.

Solution: Try running one test separately then see what error is coming.

I got the below error after running one problematic test separately where earlier I was getting the Call retries were exceeded:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: Cannot read property 'code' of undefined".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

With this, I was sure that the problem is with the catch block and when I added it in the async service API function then the test case worked perfectly fine. Maybe you can also try the same and see if it works for you or not.

I am using the below config:

node: 15.13.0

npm: 7.8.0

jest: 26.6.3

Solution 3:[3]

I was able to run the test's successfully doing the following;

  1. Install npm i -D jest-canvas-mock

Update the jest.config.ts file to have:

  export default {
...
testEnvironment: "jsdom",
setupFiles: ["jest-canvas-mock"],
}

Solution 4:[4]

Try running npm doctor using the latest npm version. It's a great tool and it helped me diagnose permission and ownership issues right away.

Takeaway:

Verify File/Folder Permissions & Ownership

Solution 5:[5]

Encountered same error when updating the vue-jest version to below listed versions

  • @vue/vue3-jest: ^27.0.0-alpha.4
  • @vue/cli-plugin-unit-jest: ~5.0.0,
  • node: v17.9.0 or v16.14.2

Error disappeared, once downgraded it to node version v14.x.x

Hunch is - the latest node versions are not compatible with the dependencies.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Harmanpreet singh
Solution 3 Steven
Solution 4 Dave
Solution 5 Shruti Chakraborty