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

[Bug]: jest unit tests hang when using jest.useFakeTimers together with fastify #12056

Closed
rburgst opened this issue Nov 9, 2021 · 4 comments
Closed

Comments

@rburgst
Copy link

rburgst commented Nov 9, 2021

Version

27.3.1

Steps to reproduce

see repro repo: https://github.com/rburgst/fastify-jest-timers

run

npm install
npm run test

Watch that the tests time out after 5s. The problem goes away when I remove jest.useFakeTimers().setSystemTime(...)

Expected behavior

the test should pass the same as without jest.useFakeTimers().setSystemTime(...)

Actual behavior

tests time out

Additional context

in fastify/help#555 they claim this is due to jest creating a "different environment" from node.js.

Environment

System:
    OS: macOS 12.0.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.15.5 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^27.3.1 => 27.3.1
@rburgst
Copy link
Author

rburgst commented Nov 9, 2021

this seems to be related to #2549 (comment), adding https://www.npmjs.com/package/jest-environment-node-single-context does indeed fix the issue

@kbanman
Copy link

kbanman commented Mar 21, 2022

Probably related to #10357, #11572, and #11607

@SimenB
Copy link
Member

SimenB commented Apr 6, 2022

Fixed via #12572 by using advanceTimers: true. Available in https://github.com/facebook/jest/releases/tag/v28.0.0-alpha.8

@SimenB SimenB closed this as completed Apr 6, 2022
@github-actions
Copy link

github-actions bot commented May 7, 2022

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 7, 2022
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

3 participants