跳到主要内容
CNode

mocha测试rest方法

问答
Wwenshiqi0发布于 11 年前最后回复 11 年前
366530

我想用mocha和should来给自己的服务器加上单元测试,但是在测试restful方法的时候遇到了问题始终抱一个错误


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)

而method的方法就是执行了一个数据库查询,并向res.body传入了一个json对象 下面是我的mocha代码


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();
                })
        })
    })
})

请指教一下,问题在哪里,这样用mocha不对嘛

查看回复

回复 (3)

W
wenshiqi0#311 年前
引用 pangguoming你用啥做的REST API? Express 还是 Restify ?

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

I
i5ting#211 年前

supertest测试

P
pangguoming#111 年前

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

参与回复

登录后即可参与回复。登录