Node.js NodeJS-Nock不';t拦截使用'request/request'模块发出的请求
在我的测试中,我试图拦截Node.js NodeJS-Nock不';t拦截使用'request/request'模块发出的请求,node.js,request,nock,Node.js,Request,Nock,在我的测试中,我试图拦截请求/request发出的HTTP请求。但它不起作用。当我使用http.request()时,nock工作得非常好。 以下是一个例子: it('A test case', function() { nock('http://www.google.com') .get('/') .reply(200, { response: 'Hello from Nock!' }); request('http://www.google.com/', fun
请求/request
发出的HTTP请求。但它不起作用。当我使用http.request()时,nock工作得非常好。以下是一个例子:
it('A test case', function() {
nock('http://www.google.com')
.get('/')
.reply(200, { response: 'Hello from Nock!' });
request('http://www.google.com/', function(err, res, body) {
console.log(body); // It displays the actual response :(
});
});
有什么见解吗
编辑:
毕竟,这是一个与代理相关的问题。您可以使用npm的请求调试模块
var request = require('request');
require('request-debug')(request);
require('request-debug')(request, function(type, data, r) {
// put your request or response handling logic here
});
请求对象中应该有您的请求数据。可能我不清楚。我希望
nock
拦截request/request
模块发出的请求。当我使用http.request
时,nock
与request/request
不兼容。您是如何设置通过代理发出的请求的测试的?您是如何修复的?我也有类似的问题。谢谢