在玩笑中为导入 PushNotificationsIOS 的组件运行快照测试时出现此错误。
"react-native": "0.63.4",
"@react-native-community/push-notification-ios": "^1.8.0",
import {NativeEventEmitter, NativeModules} from 'react-native';
^^^^^^
SyntaxError: Cannot use import statement outside a module
1 | import { Platform, AppState, Alert } from 'react-native';
> 2 | import PushNotificationIOS from '@react-native-community/push-notification-ios';
答案 0 :(得分:0)
通过在我们的 mocks.setUpTest.js 文件中模拟 PushNotificationIOS 解决:
jest.mock('@react-native-community/push-notification-ios', () => ({
checkPermissions: jest.fn(),
requestPermissions: jest.fn(),
addEventListener: jest.fn(),
addNotificationRequest: jest.fn(),
cancelLocalNotifications: jest.fn(),
}));