Skip to content

global.Promise replacement in Jest setup causing problems. #29303

@chrisbobbe

Description

@chrisbobbe

Hi! 👋

What is the purpose of replacing the global Promise in this line of jest/setup.js:

global.Promise = jest.requireActual('promise');

It looks like it was first introduced in 3ff3987 (quite a while ago) and has remained in a similar form since then. There's no explanation of this choice specifically (if I understand correctly), so I think if it must remain, it would be good to put a code comment there. 🙂

Description

'promise' refers to the NPM package with that name.

It interferes with Jest when using their new "modern" implementation of fake timers (documented here), as I describe at jestjs/jest#10221.

One interesting note on that issue, from a Jest maintainer, is this:

As an aside, one should never replace global.Promise [...]. E.g. when using async-await you will always get the native Promise regardless of the value of global.Promise.

Might it be OK and appropriate to remove the line?

React Native version:

System:
    OS: macOS 10.15.5
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 4.84 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.20.1 - ~/.nvm/versions/node/v10.20.1/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v10.20.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 25, 26, 27, 28, 29
      Build Tools: 27.0.3, 28.0.3, 29.0.2
      System Images: android-28 | Google Play Intel x86 Atom
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6241897
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.6 => 0.60.6

Steps To Reproduce

Reproduction of the issue (and more discussion) at jestjs/jest#10221.

Expected Results

React Native's Jest setup doesn't interfere with ordinary, well-documented ways of testing with Jest.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions