dataloader icon indicating copy to clipboard operation
dataloader copied to clipboard

[BUG] Use caution with `jest.useFakeTimers()`

Open leighman opened this issue 1 year ago • 1 comments

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.

leighman avatar Feb 24 '23 15:02 leighman

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

pedrorfernandes avatar Jul 05 '23 16:07 pedrorfernandes