Error: Nock: No match for request

时光怂恿深爱的人放手 提交于 2019-12-10 15:07:57

问题


I am receiving following error

{ error: 
   { Error: Nock: No match for request {
     "method": "GET",
     "url": "http://localhost:3000/admin/orders/30075889/transactions.json",
     "headers": {
       "content-type": "application/json",
       "host": "localhost:3000"
     }
   } Got instead {
     "method": "GET",
     "url": "http://localhost:3000/admin/orders/30075889/transactions.json",
     "headers": {
       "content-type": "application/json",
       "host": "localhost:3000"
     }
   }

The url is as expected, not sure what's wrong, any pointer?


回答1:


Use .log(console.log) to see the exact error message.

EX :

nock('https://test.org/sample')
.persist()
.log(console.log)
.get('/test')
.query({})
.reply(200, response);

When you use this and run the test, you will see something like this in the console

matching https://test.org/sample/test to GET https://test.org/sample/test with query({}): **true/false**.

If it says true, your request should be good. But if it says false, check both the requests and make sure they match.




回答2:


Nock interceptors don't persist by default. For every request nock needs an interceptor. It looks like you only setup interceptor once and expect it to work for every request. If you want your interceptors to persist use .persist() option something like below.

var scope = nock('http://localhost.com')
  .persist()
  .get(/.*/)
  .reply(200, 'Nock all get requests!');


来源:https://stackoverflow.com/questions/48674675/error-nock-no-match-for-request

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