【发布时间】:2022-06-11 15:02:24
【问题描述】:
我尝试使用 Jest 测试 React Native 库,但它显示错误,谁能帮我解决我的问题。
这是我的功能代码:
export const createChannel = (): void => {
PushNotification.createChannel({
channelId: 'test-channel',
channelName: 'Test Channel',
vibrate: true,
});
};
我正在对这个函数使用 react-native-push-notification 库
这是我的测试代码:
import PushNotification from 'react-native-push-notification';
import {createChannel} from '../src/functions/PomodoroFunction';
jest.mock('react-native-push-notification', () => 'PushNotification.createChannel');
describe('Create Channel unit test', () => {
it('Should be called',()=>{
const mockFN = createChannel()
expect(mockFN).toHaveBeenCalled();
})
});
显示错误:TypeError: _reactNativePushNotification.default.createChannel 不是函数
谁能帮我解决这个问题,非常感谢!
【问题讨论】:
标签: javascript react-native jestjs