DEV Community

Cover image for Jest: Exceeded Timeout of 5000 ms for a Test
Sarad Singh
Sarad Singh

Posted on

18

Jest: Exceeded Timeout of 5000 ms for a Test

Encountering this error during test runs led me to the decision to address it by adding a timeout value to the test case. After experimenting with a few values, 7000 ms emerged as the optimal choice, and hoorah! 🎉 The test passed.

On another day, rerunning the tests revealed that the same test now failed with a timeout error:

Thrown: "Exceeded timeout of 7000 ms for a test.
    Add a timeout value to this test to increase the timeout if it's a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."
Enter fullscreen mode Exit fullscreen mode

Additionally, a couple more errors appeared for other tests:

Thrown: "Exceeded timeout of 5000 ms for a test.
    Add a timeout value to this test to increase the timeout if it's a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."
Enter fullscreen mode Exit fullscreen mode

Now, one test failed for a 7000 ms timeout and two others for a 5000 ms timeout. After trial-testing with different values, settling on 10000, 7000, 8000 seemed to solve the issue! 🎉🎉

But wait! Was the battle ⚔️ against Jest test timeouts truly won? Not quite. Similar situations recurred, necessitating manual trial-tests and updates to values in specific test cases.

So, how did I overcome this never-ending battle against Jest?The answer lies in configuring Jest timeouts! 😉

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (1)

Collapse
 
pabrick profile image
Pabrick

How is this even useful? I am exausted of the void internet, only noise.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay