如何为动态 url 构建 nock 正则表达式

Bip*_*ain 4 api node.js nock

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

http://example.com/harry/potter?param1=value1
Run Code Online (Sandbox Code Playgroud)

http://example.com/harry/<value1>
Run Code Online (Sandbox Code Playgroud)

我有两种类型的 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");
    });
Run Code Online (Sandbox Code Playgroud)

了解与 node nock 一起使用的东西会很有帮助。

std*_*b-- 5

您可以将路径和查询指定为 reqex

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