mocha测试rest方法
发布于 9 年前 作者 wenshiqi0 5734 次浏览 最后一次编辑是 8 年前 来自 问答

我想用mocha和should来给自己的服务器加上单元测试,但是在测试restful方法的时候遇到了问题始终抱一个错误 <pre> <code> http #Rest method should return json by rest method: Uncaught Error: connect ECONNREFUSED at exports._errnoException (util.js:746:11) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19) </code> </pre> 而method的方法就是执行了一个数据库查询,并向res.body传入了一个json对象 下面是我的mocha代码 <pre> <code> describe(‘http’,function(){ describe(’#Rest method’,function(){ it(“should return json by rest method”,function(err,res,req){ request .get(url+’/user:wen’) .on(‘response’,function(res){ if(err)throw err; res.should.status(200).json; res.body.should.not.empty; done(); }) }) }) }) </code> </pre> 请指教一下,问题在哪里,这样用mocha不对嘛

3 回复

你用啥做的REST API? Express 还是 Restify ?

supertest测试

@pangguoming koa-route 我用的koa的框架

回到顶部