Allow fake timers other than jest
See original GitHub issueDescribe the feature you’d like:
This is an follow-on to https://github.com/testing-library/dom-testing-library/issues/939. The request is to support fake timers other than jest. For instance, jest uses @sinonjs/fake-timers under the hood, and yet it’s not possible to use @sinonjs/fake-timers directly with testing-library without jest. I would like to be able to use testing-library with @sinonjs/fake-timers without jest.
Suggested implementation:
@eps1lon had a good suggestion in https://github.com/testing-library/dom-testing-library/issues/939#issuecomment-830771708 to decouple testing-library from jest timers, and @MatanBobi suggested doing so in a way that can be set up in the configure
step instead of requiring wrappers.
Describe alternatives you’ve considered:
I have tried to manually advance the clock with clock.tick()
, and it works but causes act
warnings.
Teachability, Documentation, Adoption, Migration Strategy:
I’m not certain what, if anything, will need to be done in user land to make this work. Ideally, it could be handled under-the-hood within this library, but I’m not sure how that could be done in a robust way.
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (6 by maintainers)
According to this comment Jest fake timers are the only one supported.
I’m using jest + sinon timers, and everything was working fine for me up until the latest release.
This particular combination is a problem. dom-testing-library does some custom checking to see if jest timers are enabled (which will come back true in this case, even though jest timers are not enabled, because sinon will create a
setTimeout.clock
- any other fake timer library that creates asetTimeout.clock
would have this same problem). This library will then make calls into jest fake timers, which will raise lots of warnings from jest since fake timers are not enabled.@ChristopherChudzicki Thanks. I’ve tested with
vi.useFakeTimers({ shouldAdvanceTime: true });
and it’s working perfectly.