Hammad Qureshi
Hammad Qureshi

Reputation: 321

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)

Upvotes: 31

Views: 75003

Answers (7)

jljonnard
jljonnard

Reputation: 9

In my case jest.useFakeTimers(); does NOT work. It clears this error but creates new ones.

To avoid all these issues, I have added the following code at the beginning of each failing test with this error :

//--- Start of your file ---
//...Other imports
import { cleanup } from '@testing-library/react-native';

afterEach(cleanup);

//...Your test

Upvotes: -1

Shaive Bansal
Shaive Bansal

Reputation: 1

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

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

Upvotes: 0

Shruti Chakraborty
Shruti Chakraborty

Reputation: 11

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.

Upvotes: 1

Dave
Dave

Reputation: 19

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

Upvotes: 1

Steven
Steven

Reputation: 1177

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"],
}

Upvotes: -1

Harmanpreet singh
Harmanpreet singh

Reputation: 101

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

Upvotes: 10

Ridwan Ajibola
Ridwan Ajibola

Reputation: 1089

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

Upvotes: 13

Related Questions