DEV Community

Marc Ziel
Marc Ziel

Posted on

increasing test timeout in jest while debugging

When debugging code, the script execution takes substantially more time which sometimes leads to very strange errors when an asyc test is failed due to exceeding the time specified in jest.setTimeout which causes the next test to execute while the previous test is still running in the background.

Fortunately, we can change the default time using --setupTestFrameworkScriptFile option that should point to a file in which we change the timeout:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10 * 60 * 1000;

We can put this file in the home directory and run jest with changed timeouts from anywhere with a little bit of command line magic:

node --inspect-brk node_modules/.bin/jest --runInBand --setupTestFrameworkScriptFile="${HOME}/test-setup.js"

Another cool thing is that if we also have a setup file in our project, both files are used (but values from file given through command line option take precedence).

Top comments (0)