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

2024-03-10

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

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

and

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

我有两种类型的网址,首先是我可以使用查询参数的地方,尽管基本网址是固定的。

第二个是基本 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");
    });

了解与节点诺克一起使用的东西会有很大帮助。


您可以指定路径和查询作为正则表达式 https://github.com/node-nock/nock#specifying-path:

  nock('http://example.com')
       .get(/harry\/[^\/]+$/)
       .query({param1: 'value'})
       .reply(200, "OK");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何为动态 url 构建 nock 正则表达式 的相关文章

随机推荐