【问题标题】:Moxios Stubrequest with Regular ExpressionMoxios Stubrequest 与正则表达式
【发布时间】:2019-02-14 13:14:20
【问题描述】:

我曾尝试将 moxios Stubrequest 与 comments/.*/vote 之类的正则表达式一起使用,但它不起作用。 .* 填充有标识符(整数)。知道如何进行这项工作吗?谢谢

代码

moxios.stubRequest('/comments/.*/vote', {
        status: 200,
        response: {
            success: true
        }
    })

【问题讨论】:

    标签: vue.js vue-test-utils moxios


    【解决方案1】:

    您需要使用正则表达式而不是字符串。所以你的代码会变成:

    moxios.stubRequest(/\/comments\/.*\/vote/, {
      status: 200,
      response: {
          success: true
      }
    })
    

    【讨论】:

      【解决方案2】:

      作为额外的解决方案,您可以将 var 包装在正则表达式中

      var str = '/comments/.*/vote';
      moxios.stubRequest(new RegExp(str), {
          status: 200,
          response: {
              success: true
          }
      })
      

      【讨论】:

        猜你喜欢
        • 2019-01-29
        • 2010-09-12
        • 2011-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-04
        • 2017-12-18
        • 2017-09-27
        相关资源
        最近更新 更多