我正在尝试测试 React Native 中的链接按钮。该链接打开电子邮件服务器的 url。
在名为 SupportScreen 的父组件中使用自定义组件,如下所示:
<LinkButton
title={email}
accessibilityLabel={supportEmail}
onPress={() => Linking.openURL(`mailto:${supportEmail}`)}
/>
在模拟中:
const mockOpenURL = jest.fn();
jest.spyOn(ReactNative, 'Linking').mockImplementation(() => {
return {
openURL: mockOpenURL,
};
});
我收到一条错误消息:
Cannot spy the Linking property because it is not a function; object given instead
然后我如何实际为模拟链接编写测试?
it('should navigate to email client when pressed', () => {
const { getByLabelText } = render(<SupportScreen />);
});
});