DEV Community

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

Posted on

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! 😉

Top comments (0)