jest.setTimeout is not a function

Created on 11 Jun 2017  路  6Comments  路  Source: facebook/jest

I've added jest.setTimeout(1000); to the Getting Started sum.test.js file, but when I run ./node_modules/.bin/jest sum.test.js I get this error:

TypeError: jest.setTimeout is not a function

The documentation claims that

The jest object is automatically in scope within every test file.

Other calls, e.g. jest.clearAllTimers(), do work.

Documentation

Most helpful comment

Just do:

jasmine.DEFAULT_TIMEOUT_INTERVAL = <your_timeout>

It's a compat layer with Jasmine, currently not super documented, here's the mention: http://facebook.github.io/jest/docs/troubleshooting.html#unresolved-promises

All 6 comments

@dmitriiabramov Can you add "available in Jest 21" like we do in other places?

Is this really only available starting with v21? How was it possible to wait for long-running async calls to complete instead of the test failing with Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL ?

Just do:

jasmine.DEFAULT_TIMEOUT_INTERVAL = <your_timeout>

It's a compat layer with Jasmine, currently not super documented, here's the mention: http://facebook.github.io/jest/docs/troubleshooting.html#unresolved-promises

It's a compat layer with Jasmine, currently not super documented, here's the mention: http://facebook.github.io/jest/docs/troubleshooting.html#unresolved-promises

That's weird, I swear I had checked the Troubleshooting page but didn't see that.

UPDATE: There's a different doc under /en/ that mentions jest.setTimeout instead of jasmine.DEFAULT_TIMEOUT_INTERVAL:

http://facebook.github.io/jest/docs/en/troubleshooting.html#unresolved-promises

What's the deal with these inconsistent doc pages at almost the same URL?

@thymikee where exactly should I add jasmine.DEFAULT_TIMEOUT_INTERVAL?

test('...', (done) => {
  expect.assertions(1)

  // jest.setTimeout(10000) // not a function error
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000

  api.get().then(() => {
    done()
  }).catch((error) => {
    console.log(error)
  })
})

@rochapablo for example you can add it to your setup test framework file: http://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string
In jest 21 (or in any alpha/beta release) you'll be able to use simpler jest.setTimeout(70000); API

Was this page helpful?
0 / 5 - 0 ratings