react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

RNTL accidentally triggers `jest.useFakeTimers`

Open Niryo opened this issue 4 years ago • 0 comments

Describe the bug

I am using sinon-fake-timers together with jest, because jest's exposes only minimal part of sinon timers and I need more advanced capabilities. The thing is that React native testing library mistakenly thinks that I am using "jest.useFakeTimers", because of this check:

  if (
    typeof globalObj.setTimeout.clock !== 'undefined' &&
    // $FlowIgnore[prop-missing]
    typeof jest.getRealSystemTime !== 'undefined'
  )

The first statement is true because I am using sinon fake timers, and the second is true because I am using jest, so it assumes that I am using jest.useFakeTimers, and it automatically turn it on for me here:

  if (fakeTimersType) {
    jest.useFakeTimers(fakeTimersType);
  }

This results in both custom sinon timer and jest's fake timers being installed, and it causes issues in my tests.

Expected behavior

jest.useFakeTimers should not be called if the user didn't call it explicitly.

Steps to Reproduce

use jest 27 and sinon-fake-timers

Versions

npmPackages: @testing-library/react-native: ^9.0.0 => 9.0.0 react-test-renderer: ^17.0.2 => 17.0.2

Niryo avatar Dec 29 '21 10:12 Niryo