Node.js Nodejs API测试使用SuperTest引发套接字挂起错误

Node.js Nodejs API测试使用SuperTest引发套接字挂起错误,node.js,http,express,mocha.js,supertest,Node.js,Http,Express,Mocha.js,Supertest,我正在尝试使用mocha将单元测试添加到我的nodejs应用程序中 我已经创建了一个虚拟测试端点'/test',它返回一个字符串,如下所示: { Error: socket hang up at createHangUpError (_http_client.js:322:15) at Socket.socketOnEnd (_http_client.js:425:23) at Socket.emit (events.js:187:15) at endReadableNT (_stream_re

我正在尝试使用mocha将单元测试添加到我的nodejs应用程序中

我已经创建了一个虚拟测试端点
'/test'
,它返回一个字符串,如下所示:

{ Error: socket hang up
at createHangUpError (_http_client.js:322:15)
at Socket.socketOnEnd (_http_client.js:425:23)
at Socket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19) code: 'ECONNRESET', response: undefined }
测试终点:

app.get(routeHelper.getURLPath('/test'), (req, res, next) => {
 res.send('Helloo from test route !!');
 next();
});
sample.test.js:

process.env.NODE_ENV = 'test';
let supertest = require("supertest");
let should = require("should");

let server = supertest.agent("http://localhost:9000");

describe('Routes', () => {

  it('sample test', (done) => {

    server
      .get("/test")
      .expect(200)
      .end(function(err,res){
       // console.log('***************Ressssssss*******   ', res.body);
        console.log('***************errrrrrrrrrrrrrr*******   ', err);
        res.status.should.equal(200);
        res.body.error.should.equal(false);
        done();
      });
    });
});
当我运行测试时,它抛出如下所示的错误:

{ Error: socket hang up
at createHangUpError (_http_client.js:322:15)
at Socket.socketOnEnd (_http_client.js:425:23)
at Socket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19) code: 'ECONNRESET', response: undefined }
直接从浏览器访问API可以正确地给出响应。但是,当我运行测试时,它抛出了这个错误


任何修复此问题的帮助都将非常有用

您正在将代理设置为主机,它将期望服务正在运行。确保应用程序正在端口上运行。@AbhikChakraborty应用程序正在运行。如果我在浏览器中点击端点,它就会工作。由于它看起来很模糊,不确定出了什么问题,我只看到一件事,那就是使用
next()
as
send()
将调用
end()
以结束请求-响应生命周期。实际上,我需要编写相同的代码并进行尝试。您是否修复过它?