Skip to content
Advertisement

How to mock Push notification native module in React native jest tests?

When using the module react-native-push-notification, I had this error:

JavaScript

I tried to mock the module by creating __mocks__/react-native.js and putting this code within it:

JavaScript

Now, I have this error:

JavaScript

How I could mock fully this module the right way?

Advertisement

Answer

I mocked the module PushNotificationIOS by creating a setup file jest/setup.js:

JavaScript

I’ve configured jest to run this setup file by adding this line into packages.json:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement