Skip to content

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

@rburgst

Description

@rburgst

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions