jest: [Possible regression] jest.setTimeout not honored
After updating to ^27.0.3
this morning, a bunch of previously working tests started to fail, with error messages below:
thrown: "Exceeded timeout of 5000 ms for a test.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
I did have jest.setTimeout(300000)
in place and it was working fine before, hence I’m doubting there might be a regression issue here.
As a side note, after adding a global timeout in the jest config the problems went away, hence it’s most likely a jest.setTimeout
regression, might worth looking into.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 47
- Comments: 29 (2 by maintainers)
Commits related to this issue
- Move `jest.setTimeout()` to top level to fix possible regression See https://github.com/facebook/jest/issues/11500 — committed to wearerequired/lint-action by ocean90 3 years ago
- Bump jest from 26.6.3 to 27.0.3 (#246) * Bump jest from 26.6.3 to 27.0.3 Bumps [jest](https://github.com/facebook/jest) from 26.6.3 to 27.0.3. - [Release notes](https://github.com/facebook/jest/r... — committed to wearerequired/lint-action by dependabot[bot] 3 years ago
- chore: move test timeouts to top-level see https://github.com/facebook/jest/issues/11500 — committed to owid/owid-grapher by marcelgerber 3 years ago
- test: move `jest.setTimeout` to top of the file ref. https://github.com/facebook/jest/issues/11500 — committed to kintone/js-sdk by zaki-yama 3 years ago
- test(data-loader): move `jest.setTimeout` to top of the file (#1024) * test: move `jest.setTimeout` to top of the file ref. https://github.com/facebook/jest/issues/11500 * chore: extend timeou... — committed to kintone/js-sdk by zaki-yama 3 years ago
- test(data-loader): move `jest.setTimeout` to top of the file (#1024) * test: move `jest.setTimeout` to top of the file ref. https://github.com/facebook/jest/issues/11500 * chore: extend timeou... — committed to kintone/cli-kintone by zaki-yama 3 years ago
- test(data-loader): move `jest.setTimeout` to top of the file (#1024) * test: move `jest.setTimeout` to top of the file ref. https://github.com/facebook/jest/issues/11500 * chore: extend timeou... — committed to kintone/cli-kintone by zaki-yama 3 years ago
- test(data-loader): move `jest.setTimeout` to top of the file (#1024) * test: move `jest.setTimeout` to top of the file ref. https://github.com/facebook/jest/issues/11500 * chore: extend timeou... — committed to kintone/cli-kintone by zaki-yama 3 years ago
I believe
setTimeout
is not being mocked correctly in Jest 27. I’m finding thatgives
I’m seeing the same thing with
jest@27.0.3
The new default “modern” timer mocking works as expected. However asserting
expect(setTimeout).toHaveBeenCalled...
reports the[Function setTimeout]
as stated by @s100Reverting to the legacy timer mocks works ok, e.g.
Maybe try Sinon?
Got the same issue updating from
jest@26
tojest@^28.1.0
. Sorry if I sound entitled, but how is this still an issue a year (and a major version) after the original report of this issue?I have the same issue, is there any plan to fix that?
Since this issue is labeled “needs repro”, I’m going to point to a related issue with a repro: https://github.com/facebook/jest/issues/11543
Just ran into this and it’s now holding up an upgrade for us too.
Hello, everyone. I moved
jest.setTimeout(600000)
to top level and I have an timeout error 600ms. are there any solution for this issue? Thanks so much.TimeoutError: Element .breadcrumb-container not found waiting for function failed: timeout 600ms exceeded
We saw this as well with jest.setTimeout for our tests when migrating from 26 -> 27. We had only one particularly long running test and so we were calling that function within the test body to increase the timeout default. (As the CLI suggests!)
We have migrated to passing the timeout argument to the test directly as the trailing argument as well as the afterEach and it appears to have resolved the issue.
Yep. Just as documented here: https://jestjs.io/docs/timer-mocks
So I’m following this tutorial (sinon implementation @11:00) and still got issues.
cannot assign read only property 'performance' of object '#<object>'
thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
Although I’m testing a rest api endpoint that finds an item by id (findById).
Do you have any idea of how to go about it? Tried every supposed solution.
I’m having this issue currently. Have you been able to solve it without having to downgrade?
@Smrtnyk That fits with what I’m seeing.
If modern timers are not going to conform to the mock signature then the documentation should be updated to reflect it. The Timer Mocks documentation for v26 recommends using the failing approach. https://jestjs.io/docs/timer-mocks
Hello!
I am currently having the same problem. I tried using
jest.setTimeout
,testTimeout
or even set the timeout on the test but nothing is working…I had to downgrade jest and babel-jest for now. I downgraded jest to 26.6.3 and babel-jest to 25.5.1. Any version after that broke my tests.
Thank you!