Jest: Make jasmine.DEFAULT_TIMEOUT_INTERVAL configurable

Created on 16 Dec 2015  路  24Comments  路  Source: facebook/jest

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

Most helpful comment

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)

All 24 comments

:+1:

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.

if you need it in every test you can set it in the setup-env file.

@cpojer Where / how?

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

Thanks for the clarification. I my setupfile, I tried setting jasmine.DEFAULT_TIMEOUT_INTERVAL but it says Jasmine isn't there. I ended up putting the line in the test itself.

I can only access jasmine from "setupTestFrameworkScriptFile".

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

These docs apparently don't exist anymore. How can I configure that timeout interval in the current version?

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)

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.

@jzaefferer Add it to the test file itself

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)

@sudhanshuraheja thanks, that works ;) although I found a way to avoid doing that altogether

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

@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.

So what's the correct way of setting timeouts globally? The URLs in this issue are obsolete

@benjick Per https://facebook.github.io/jest/docs/en/troubleshooting.html#unresolved-promises

jest.setTimeout(10000); // 10 second timeout

I do this in a setup file (https://facebook.github.io/jest/docs/en/configuration.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

future references, this worked for me

Yep that's what I did as well

@sudhanshuraheja Thanks for the tip!

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);
      }
    );
  });
}

jest.setTimeout(10000) in setupTestFrameworkScriptFile works

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.

Was this page helpful?
0 / 5 - 0 ratings