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

Rejected Promises in test causes test to "fail" with error ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.

Open nero2009 opened this issue 2 years ago • 3 comments

New Version

0.72.3

Old Version

0.70.3

Build Target(s)

all

Output of react-native info

System:
  OS: macOS 13.0.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 77.75 MB / 32.00 GB
  Shell:
    version: 5.8.1
    path: /bin/zsh
Binaries:
  Node:
    version: 16.18.1
    path: ~/.nvm/versions/node/v16.18.1/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v16.18.1/bin/yarn
  npm:
    version: 8.19.2
    path: ~/.nvm/versions/node/v16.18.1/bin/npm
  Watchman:
    version: 2023.05.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/mac/.rvm/rubies/ruby-2.7.5/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2021.3 AI-213.7172.25.2113.9123335
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.18
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/mac/.rvm/rubies/ruby-2.7.5/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.3
    wanted: 0.72.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Issue and Reproduction Steps

Describe the bug

I just upgraded from react native 0.70 to 0.72 and some of my tests that used to pass on my CI started to fail. The test suite passses but the test exits with an error.


ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From App.test.js.

      19 |     console.log('ran 2344')
      20 |     } catch (error) {
    > 21 |       Alert.alert('Error', error)
         |       ^
      22 |     }
      23 |    
      24 |   }

      at Object.get Alert [as Alert] (node_modules/react-native/index.js:94:12)
      at Alert (App.js:21:7)
          at Generator.throw (<anonymous>)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
/Users/mac/Documents/work/side/failedPromises/App.js:26
        _reactNative.Alert.alert('Error', error);
                           ^

TypeError: _reactNative.Alert.alert is not a function
    at /Users/mac/Documents/work/side/failedPromises/App.js:26:28
    at Generator.throw (<anonymous>)
    at asyncGeneratorStep (/Users/mac/Documents/work/side/failedPromises/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _throw (/Users/mac/Documents/work/side/failedPromises/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)

This might be related to this PR https://github.com/facebook/react-native/commit/f1fdc8b9b636e010ae5d5e737fc81a8da8f536d4 cos if I add global.Promise = jest.requireActual('promise'); to my jest.setup.js file the test behave like it was pre 0.71

Expected behavior

Expected bahavior is for this not to break the CI but maybe throw a warning

Steps to Reproduce

  • clone https://github.com/nero2009/promise-reject-repro
  • install deps
  • run npm run test

Versions

npmPackages: @testing-library/react-native: ^12.2.0 => 12.2.0 react: 18.2.0 => 18.2.0 react-native: 0.72.3 => 0.72.3 react-test-renderer: ^18.2.0 => 18.2.0

nero2009 avatar Aug 08 '23 12:08 nero2009

@nero2009 Had same issue after upgrading to RN v0.72

michtntbrighte avatar Aug 09 '23 00:08 michtntbrighte

FYI @robhogan for the blamed diff removing promise polyfill.

NickGerleman avatar Aug 16 '23 07:08 NickGerleman

Same issue

VadimZP avatar Feb 04 '24 11:02 VadimZP

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

react-native-bot avatar Aug 03 '24 05:08 react-native-bot

This issue was closed because it has been stalled for 7 days with no activity.

react-native-bot avatar Aug 10 '24 05:08 react-native-bot