如何为动态网址构建Nock正则表达式 [英] How to build nock regex for dynamic urls

查看:127
本文介绍了如何为动态网址构建Nock正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do i build nock configuration for the following types of urls

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

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

我有两种类型的url,第一种是我可以在基本url固定的情况下拥有查询参数.

I have two type of urls first is where i can have query params altough the base url is fixed.

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

Second one is where base url has dynamic values.

当前我有

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配合使用的知识将大有帮助.

Would be of great help to know something that works with node nock.

推荐答案

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

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

这篇关于如何为动态网址构建Nock正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆