react-native - TypeError:_reactNativePushNotification.default.localNotificationSchedule 在编写单元测试时不是函数
问题描述
我无法为以下代码编写单元测试
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 })
}
解决方案
这是模拟的方式
jest.mock('react-native-push-notification', () => ({
configure: jest.fn(),
onRegister: jest.fn(),
onNotification: jest.fn(),
addEventListener: jest.fn(),
requestPermissions: jest.fn()
}))
推荐阅读
- asp.net - 根据我的 SQL 数据库中的用户角色和位置限制对 ASP.NET VB Web 表单应用程序中页面的访问?
- routes - Symfony 5 - 国际化路由 - 带有空或动态区域设置的前缀路由
- fortran - 将派生类型作为可选参数传递时出现分段错误
- azure - 如何使用 ARM 模板副本有条件地为存储帐户提供 N 个角色分配?
- c# - 按列名对 DataView 行进行排序
- snowflake-cloud-data-platform - 雪花 - 期待 VARIANT 但使用 MERGE 获得 VARCHAR 列
- docker - docker撰写网络别名不起作用
- python - Python 中缺少 ByteCounts 标记
- node.js - 如何更改媒体字段上传提供者?
- cuda - 有没有办法为 CUDA 设置多个 gpu?