When trying to run tests on Jest for my app which uses react-native-fcm I get error:
Invariant Violation: Native module cannot be null.
at invariant (node_modules/fbjs/lib/invariant.js:44:15)
at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:32:1)
at Object.<anonymous> (node_modules/react-native-fcm/index.js:3:18)
at Object.<anonymous> (app/components/MyComponent.js:6:21)
(MyComponent.js:6 is import FCM from 'react-native-fcm';)
Version info:
[email protected]
[email protected]
This problem has been earlier reported, but closed as https://github.com/evollu/react-native-fcm/issues/435
shouldn't jest just mock out the whole FMC package?
Does this issue happen for other 3rd party react native packages?
I didn't get this issue for other 3rd party react-native packages in my project, which included e.g.:
"react-native-communications": "^2.2.1",
"react-native-config": "^0.3.1",
"react-native-google-analytics-bridge": "^5.0.1",
"react-native-maps": "^0.15.2",
"react-native-menu": "^0.20.2",
"react-native-permissions": "^1.0.0"
try replace this like https://github.com/evollu/react-native-fcm/blob/master/index.js#L3
with const EventEmitter = new NativeEventEmitter(NativeModules.RNFIRMessaging || {});
Hey @evollu,
That seemed to fix the problem.
Thank you for the temporary fix!
will update code
fixed in 9.7.2
Most helpful comment
will update code
fixed in 9.7.2