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 unit tests hang when using jest.useFakeTimers #555
Comments
I don't know why this is happening. It's likely because of Jest own environment. I personally won't have time to work on this, but a PR would be highly appreciated. (Generically I do not recommend to use Jest for testing Node.js applications) |
I moved this issue to help. |
Please file an issue with Jest. They create a new environment. We target Node.js. |
just for the record, we have countless repos with both fastify and jest and so far this combination has worked pretty great. So I am quite surprised about the statement
@mcollina do you have further details on why this would be the case? |
jestjs/jest#2549 and a lot of other issues. To be honest it works fine 99% of the time but that remaining 1% keeps biting teams across the globe and they spend days trying to understand why things do not work as they expect to work as they do when running Node.js proper. Regarding your problem, I think you are missing a call to run all the pending timers: https://jestjs.io/docs/timer-mocks. |
hmm, for the record, using |
This seems to be related to plugin registration somehow. It also hangs if one does |
It seems From the docs: /**
* If set to `true` all timers will be advanced automatically by 20 milliseconds
* every 20 milliseconds. A custom time delta may be provided by passing a number.
* The default is `false`.
*/
advanceTimers?: boolean | number; |
Prerequisites
Fastify version
3.23.1
Plugin version
No response
Node.js version
14.18
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
Monterey
Description
When using fastify in a jest unit test calling
causes the
server.inject
call to stall forever.Steps to Reproduce
see repro repo: https://github.com/rburgst/fastify-jest-timers
Expected Behavior
it should be possible to mock the current system time using
jest.useFakeTimers().setSystemTime(...)
The text was updated successfully, but these errors were encountered: