react-native-google-mobile-ads
react-native-google-mobile-ads copied to clipboard
[🐛] Jest Setup file is deleting `TurboModuleRegistry.get`, breaking test suites
What happened?
In my Jest Config file, I am adding ./node_modules/react-native-google-mobile-ads/jest.setup.ts
to my setupFiles
config. This always worked for me until I decided to begin upgrading my libraries. That's when I started getting errors such as this in my test suite:
It took me a long time to find out the culprit, and apparently it's this file under react-native-google-mobile-adds
. Notice how it assigns getEnforcing
but not a get
to the TurboModulesRegistry
library:
jest.doMock('react-native', () => {
return Object.setPrototypeOf(
{
Platform: {
OS: 'android',
select: () => {},
},
NativeModules: {
...ReactNative.NativeModules,
RNAppModule: {
addListener: jest.fn(),
removeListeners: jest.fn(),
eventsAddListener: jest.fn(),
eventsNotifyReady: jest.fn(),
},
RNGoogleMobileAdsModule: {
addListener: jest.fn(),
removeListeners: jest.fn(),
eventsAddListener: jest.fn(),
eventsNotifyReady: jest.fn(),
},
RNGoogleMobileAdsInterstitialModule: {
interstitialLoad: jest.fn(),
},
RNGoogleMobileAdsRewardedModule: {},
RNGoogleMobileAdsConsentModule: {},
},
TurboModuleRegistry: {
getEnforcing: () => {
return {
initialize: jest.fn(),
setRequestConfiguration: jest.fn(),
openAdInspector: jest.fn(),
openDebugMenu: jest.fn(),
setAppVolume: jest.fn(),
setAppMuted: jest.fn(),
};
},
},
},
ReactNative,
);
});
I think we need to better document how to setup react-native-google-mobile-ads
with Jest, as well as fixing this mock for future users.
Platforms
Android and iOS
React Native Info
Not applicable.
Are your using Typescript?
- [X] My project is using Typescript
package.json
Not applicable.
app.json
Not applicable.
ios/Podfile
Not applicable.
android/build.gradle
Not applicable.
android/app/build.gradle
Not applicable.
android/settings.gradle
Not applicable.
AndroidManifest.xml
Not applicable.