【问题标题】:How to build nock regex for dynamic urls如何为动态网址构建 nock 正则表达式
【发布时间】:2018-05-15 22:36:56
【问题描述】:

如何为以下类型的 url 构建 nock 配置

http://example.com/harry/potter?param1=value1

http://example.com/harry/<value1>

我有两种类型的 url,首先是我可以有查询参数,尽管基本 url 是固定的。

第二个是基本 url 具有动态值的位置。

目前我有

before(function(){
   nock('http://example.com')
       .get('/terminal/chrome_log')
       .reply(200, "OK");

  nock('http://example.com')
       .get(function(uri) {
           return uri.indexOf('harry') >= 0;
       })
        .reply(200, "OK");
    });

了解一些适用于节点诺克的知识会很有帮助。

【问题讨论】:

    标签: node.js api nock


    【解决方案1】:

    您可以指定path and query as reqex:

      nock('http://example.com')
           .get(/harry\/[^\/]+$/)
           .query({param1: 'value'})
           .reply(200, "OK");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      • 2014-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      相关资源
      最近更新 更多