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

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

问题描述

我如何为以下类型的 url 构建 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");
    });

了解一些适用于 node nock 的东西会有很大帮助.

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

推荐答案

您可以指定 path并查询为 reqex:

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

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

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