Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest.setTimeout is not a function #3788

Closed
dandv opened this issue Jun 11, 2017 · 7 comments
Closed

jest.setTimeout is not a function #3788

dandv opened this issue Jun 11, 2017 · 7 comments
Assignees

Comments

@dandv
Copy link
Contributor

dandv commented Jun 11, 2017

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.

@cpojer
Copy link
Member

cpojer commented Jun 11, 2017

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

@dandv
Copy link
Contributor Author

dandv commented Jun 11, 2017

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 ?

@thymikee
Copy link
Collaborator

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

@dandv
Copy link
Contributor Author

dandv commented Jun 11, 2017

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?

@rochapablo
Copy link

rochapablo commented Aug 30, 2017

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

@thymikee
Copy link
Collaborator

@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

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants