TypeError:_reactNativePushNotification.default.localNotificationSchedule在编写单元测试时不是函数

时间:2019-09-18 06:21:09

标签: react-native jestjs enzyme react-native-push-notification

我无法为以下代码编写单元测试

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 })
}

2 个答案:

答案 0 :(得分:1)

这是模拟的方式

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

答案 1 :(得分:0)