如何编写jest测试以在react native中打开URL?

呵呵 测试交流2109字数 337阅读模式
摘要我正在尝试编写一个测试用例,用于在我的react原生应用程序中测试URL。这是我的模拟 从“导入{Linking}”;反应本机“;; 开玩笑mock('react-native/L...

我正在尝试编写一个测试用例,用于在我的react原生应用程序中测试URL。这是我的模拟

import { Linking } from "react-native";
jest.mock('react-native/Libraries/Linking/Linking', () => {
  return {
    openURL: jest.fn()
  }
})
Linking.openURL.mockImplementation(() => true)

这是我的测试文章源自玩技e族-https://www.playezu.com/193938.html

test('open google url',async ()=>{
  expect(Linking.openURL()).toHaveBeenCalled('https://www.google.com/')
})

但是我得到了这个错误,我该怎么办?文章源自玩技e族-https://www.playezu.com/193938.html

软件项目功能测试文章源自玩技e族-https://www.playezu.com/193938.html 文章源自玩技e族-https://www.playezu.com/193938.html

玩技站长微信
添加好友自动发送入群邀请
weinxin
rainbow-shownow
玩技官方公众号
官方微信公众号
weinxin
PLAYEZU
 
  • 版权提示:本站仅供存储任何法律责任由作者承担▷诈骗举报◁▷新闻不符◁▷我要投稿◁
    风险通知:非原创文章均为网络投稿真实性无法判断,侵权联系2523030730
    免责声明:内容来自用户上传发布或新闻客户端自媒体,切勿!切勿!切勿!添加联系方式以免受骗。
  • 原创转载:https://www.playezu.com/193938.html
    转载说明: 点我前往阅读>>>
评论  2  访客  2
    • Gieto
      Gieto 9

      如果我理解你的问题,那么你可以使用react native webview。
      import WebView from ‘react-native-webview’;

      export const WebView: React.FC<Props> = ({route}) => {
      const {url} = route.params;

      <WebView
      source={{uri: url}}
      />
      );
      };

      这就是我如何使用我的网络视图屏幕来打开任何需要打开的url(如条款和条件等)

      • Atif Aziz
        Atif Aziz 9

        你试过这样吗。?
        test(‘open google url’,async ()=>{
        expect(Linking.openURL(‘https://www.google.com/’)).toHaveBeenCalled()
        }).

      匿名

      发表评论

      匿名网友
      确定