Jest Call retries were exceeded

May 2024 ยท 2 minute read

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) 
6

6 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

3

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

1

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

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

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

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

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

  • Install npm i -D jest-canvas-mock
  • Update the jest.config.ts file to have:

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

    Use this, it works for me: axios.get.mockImplementation(() => Promise.resolve({ data: [] }));

    PS: change get to post incase you are using POST method.

    1

    ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobWlwYWx%2FeIGOo5ysrF2Yrq24jKucraqZmsBuw8SrnGadqJiyprDEnQ%3D%3D