Skip to content

RNTL accidentally triggers jest.useFakeTimers #886

Description

@Niryo

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

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions