jest: Make jasmine.DEFAULT_TIMEOUT_INTERVAL configurable

5 seconds can be really annoying if you have many test cases that fail.

I’m not sure what would be the best option to accomplish this, but I imagine a configurable option in package.json. Something like defaultTimeoutInterval, which would then be passed to jasmine used.

Steps:

  • Pass jest json config to jasmine file (not sure how)
  • Change jasmine.DEFAULT_TIMEOUT_INTERVAL to jestConfig.defaultTimeoutInterval || 5000

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 8
  • Comments: 25 (6 by maintainers)

Most upvoted comments

5000 works well as a global config, if you want to change the timeout for a specific test, please do this

test("test an API which takes time", () => {

    doYourThing()

}, 10000)

I think it is enough to set this on a per-test level. This already works. If you need it in every test you can set it in the setup-env file.

While this issue is closed, I just ran into it as well, and couldn’t figure out a solution. Nothing in here nor in #896 helped.

Specifically, adding jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; to the file configured as setupTestFrameworkScriptFile resulted in Cannot find module 'jasmine' from 'testSetup.js'

to indicate that Jasmine’s it has an optional timeout third argument?

I tried that, too, but it didn’t make any difference.

npm uninstall jest --save

Best solution

Or delete the timeout code in que_runner.js

Making config and setup doesn’t work

// A specialized version of `p-timeout` that does not touch globals.
// It does not throw on timeout.
function pTimeout(promise) {
  return new Promise((resolve, reject) => {
    promise.then(
      val => {
        resolve(val);
      },
      err => {
        reject(err);
      }
    );
  });
}

Sorry, I mean the setupFiles config option: http://facebook.github.io/jest/docs/api.html#setupfiles-array

Thanks for that @jordansexton, just a note though, it doesn’t seem to work if using the setupFiles config, only with the setupTestFrameworkScriptFile which runs after the test framework has been installed, so the correct documentation URL is: https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string

Somebody should send a PR for jest.setTestTimeout(time) so we have an official forward-looking API for this.

May I suggest improving the API reference and troubleshooting section in the docs to indicate that Jasmine’s it has an optional timeout third argument? (willing to do that PR if you want)

setupTestFrameworkScriptFile is now deprecated, so the way to get this working is to add

  "setupFilesAfterEnv": [
    "<rootDir>/src/__test__/setup.js"
  ]

to the jest property of your package.json or jest.config.* file, and add jest.setTimeout(n) to src/__test__/setup.js.

@sudhanshuraheja Thanks for the tip!

@warent I don’t remember exactly what the issue was, but I wasn’t using fake timers correctly. After I fixed the issue with fake timers in my test, there was no need for increased timeout.

@phil-r care to share with the rest of the class? 😄

Phew, I’m sorry again. setupFiles actually runs before we set-up jasmine. We have setupTestFrameworkScriptFile which runs after jasmine and before your test.