Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 607
Hammad Qureshi Avatar asked Mar 23 '20 16:03

Hammad Qureshi


3 Answers

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

like image 110
Ridwan Ajibola Avatar answered Nov 09 '22 08:11

Ridwan Ajibola


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

like image 36
Harmanpreet singh Avatar answered Nov 09 '22 07:11

Harmanpreet singh


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

like image 1
Dave Avatar answered Nov 09 '22 09:11

Dave