我想要类似以下内容(实际上有效...):
import { NativeModules } from 'react-native';
import PushNotifications from '../../app/platform/PushNotificationSupport';
const mockRNA = jest.requireMock('react-native');
jest.mock('react-native', () => {
return {
default: mockRNA.default,
NativeModules: {
...mockRNA.NativeModules,
NativePushNotifications: {
setTokenHandler: jest.fn(),
},
},
};
});
当然,上面的代码实际上不起作用。我本质上是想在现有react-native
模拟的基础上构建。
答案 0 :(得分:0)
您可以尝试直接模拟NativeModules
jest.mock('NativeModules', () => ({
NativePushNotifications: {
setTokenHandler: jest.fn(),
},
...
}));