Search code examples
react-nativejestjsenzymereact-native-push-notification

TypeError: _reactNativePushNotification.default.localNotificationSchedule is not a function while writing unit test


I am not able to write unit test for the following code

import PushNotification from 'react-native-push-notification'
import { timeZoneForNotification } from '../Assets/Constants/constants'
import firebase from 'react-native-firebase'
export const scheduleNotification = ({ 
    title = timeZoneForNotification.title, 
    message 
 },
  date
) => {
  PushNotification.localNotificationSchedule({ title, message, date })
}

Solution

  • Here is the way to mock

    jest.mock('react-native-push-notification', () => ({
      configure: jest.fn(),
      onRegister: jest.fn(),
      onNotification: jest.fn(),
      addEventListener: jest.fn(),
      requestPermissions: jest.fn()
    }))