我正在使用nodev6.2.0,并通过Mocha & Chai对其进行测试。
我编写了一个api,当我用postman /网站/节点CLI测试它时,它工作得很好,但是当我使用mocha测试它时,我得到了一个错误:
{错误:连接ECONNREFUSED 127.0.0.1:4001代码:“ECONNREFUSED”,errno:“ECONNREFUSED”,syscall:“connect”,地址:'127.0.0.1',端口: 4001 }
现在,问题是,在http://localhost:4001上测试连接的先前测试很好.
这是测试代码-
describe('/api/getAlbums', function () {
this.timeout(5000);
it('should get an array of 4 objects', function (done) {
http.get('http://localhost:4001/api/getAlbums?uid=some_uid', function (res) {
console.log(`Got response: ${res.statusCode}`);
done();
}).on('error', (e) => {
console.log(`Got error: ${e.message}`);
console.log('e', e);
done();
});
});
});同样,当我在CLI中运行相同的函数(没有done();)时,它工作得很好。
我看了很多文件,但什么也找不到,我很想得到你的帮助,谢谢。
发布于 2016-05-31 08:51:39
问题的根源不是恶魔。好像有个同步问题。我已经将“test”文件夹添加到nodemon.json的“忽略”中,现在一切都正常了。
https://stackoverflow.com/questions/37540640
复制相似问题