Any 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(R) Core(TM) 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
Describe what you expected to happen:
The tests should run
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',
}),
}),
)
same issue
I believe this is a duplicate of https://github.com/facebook/react-native/issues/26579#
I'm having a similar issue with Animated. Under the hood it uses Platform.isTesting() to determine if AnimatedMock.js should be used but that method is returning undefined for this.constants.isTesting https://github.com/facebook/react-native/blob/85ac9cf6c7e33f6b5b97df7b2560c1da67976e56/Libraries/Utilities/Platform.ios.js#L58
I'm currently working around it with the following...
jest.mock(
'react-native/Libraries/Utilities/Platform',
(): object => ({
...require.requireActual('react-native/Libraries/Utilities/Platform'),
isTesting: (): boolean => true,
})
);
AnimatedMock.js file is probably broken, see this:
The empty animation doesn't invoke it's callback when the start is not overriden:
// Current impl
const emptyAnimation = {
start: () => {},
...
}
// Should be like this:
const emptyAnimation = {
start: (cb) => { cb && cb({ finished: true }) },
}
And other mocks like parallel, sequence and stagger don't ever call start of the animation list arg
// Current impl
const parallel = function(
animations: Array<CompositeAnimation>,
config?: ?ParallelConfig,
): CompositeAnimation {
return emptyAnimation;
};
// Should be like this
const parallel = function(
animations: Array<CompositeAnimation>,
config?: ?ParallelConfig,
): CompositeAnimation {
return {
...emptyAnimation,
start: (callback) => {
animations.forEach(it => it.start && it.start())
callback && callback({finished: true});
}
};
};
There's also the decay which never sets the toValue arg and event which doesn't do anything
If any lib is using the animations start callback to set some state or do anything, in testing mode they're broken. This is causing issues for our tests (which can be related to this https://github.com/wix/Detox/issues/1513)
Edit:
Here's my fixed version for that file: https://gist.github.com/Grohden/0abd03cc0e7f50266d82f88a9feba9f7
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.
Most helpful comment
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', }), }), )