Jest - RN 0.61.1 Platform issue
See original GitHub issueAny test that uses something from react-native (such as Platform) gives the error TypeError: _NativePlatformConstantsIOS.default.getConstants is not a function
All these tests are working in 0.59.5 but are broken in 0.61.x.
React Native version:
System: OS: macOS Mojave 10.14.4 CPU: (12) x64 Intel® Core™ i7-8750H CPU @ 2.20GHz Memory: 1.40 GB / 16.00 GB Shell: 5.3 - /bin/zsh Binaries: Node: 8.11.4 - ~/.nvm/versions/node/v8.11.4/bin/node Yarn: 1.13.0 - ~/.yvm/versions/v1.13.0/bin/yarn npm: 6.7.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 Android SDK: API Levels: 23, 24, 25, 26, 27, 28 Build Tools: 28.0.3 System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom IDEs: Android Studio: 3.4 AI-183.6156.11.34.5692245 Xcode: 10.3/10G8 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.1 => 0.61.1 npmGlobalPackages: react-native-cli: 2.0.1
Steps To Reproduce
- Run jest.
Describe what you expected to happen:
The tests should run
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:7 (1 by maintainers)
Top GitHub Comments
For anyone reading this i found a temporary solution because its not good to be linked to the path of the library.
jest.mock( 'react-native/Libraries/Utilities/NativePlatformConstantsIOS', () => ({ ...require.requireActual( 'react-native/Libraries/Utilities/NativePlatformConstantsIOS', ), getConstants: () => ({ forceTouchAvailable: false, interfaceIdiom: 'en', isTesting: false, osVersion: 'ios', reactNativeVersion: { major: 60, minor: 1, patch: 0, }, systemName: 'ios', }), }), )
I’m having a similar issue with
Animated
. Under the hood it usesPlatform.isTesting()
to determine ifAnimatedMock.js
should be used but that method is returningundefined
forthis.constants.isTesting
https://github.com/facebook/react-native/blob/85ac9cf6c7e33f6b5b97df7b2560c1da67976e56/Libraries/Utilities/Platform.ios.js#L58I’m currently working around it with the following…