Skip to content

[BUG] Use caution with jest.useFakeTimers() #339

@leighman

Description

@leighman

Just spent ages debugging why our tests were breaking when using DataLoader and eventually discovered that since we were using jest.useFakeTimers() it was never resolving the batch.
Would be good to have some kind of warning about this in the readme.

Activity

pedrorfernandes

pedrorfernandes commented on Jul 5, 2023

@pedrorfernandes

it works with

jest.useFakeTimers({ advanceTimers: true });
// OR 
jest.useFakeTimers({ doNotFake: ["nextTick"] }); // if you really don't want process.nextTick to be monkey patched

because dataloader uses process.nextTick (if in node)

however, I still haven't figured out how to advance the timers properly to test the dataloader itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @leighman@pedrorfernandes

        Issue actions

          [BUG] Use caution with `jest.useFakeTimers()` · Issue #339 · graphql/dataloader