如何为以下类型的网址构建nock配置
http://example.com/harry/potter?param1=value1
和
http://example.com/harry/<value1>
我有两种类型的网址首先是我可以查询参数,尽管基本网址是固定的。
第二个是基本网址具有动态值的位置。
目前我有
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");
});
知道与节点nock一起使用的东西会有很大的帮助。
答案 0 :(得分:3)
您可以指定path and query as reqex:
nock('http://example.com')
.get(/harry\/[^\/]+$/)
.query({param1: 'value'})
.reply(200, "OK");