How to build nock regex for dynamic urls

限于喜欢 提交于 2019-12-07 22:30:45

问题


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

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

and

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

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

Second one is where base url has dynamic values.

Currently i have

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");
    });

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


回答1:


You can specify path and query as reqex:

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


来源:https://stackoverflow.com/questions/47599884/how-to-build-nock-regex-for-dynamic-urls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!