【发布时间】:2014-02-27 05:54:03
【问题描述】:
我正在使用 supertest 和 mocha 测试我的 express rest api。 有这个测试用例我想用 supertest:expect(function(res){ }) 的方法检查返回的响应体。但是我遇到了一个我不知道为什么的错误:
Error: expected [Function] response body, got '{"name":"Aaron Shen","_id":"
530ed1ce92788ed031022d8c","__v":0,"active":true}'
有人知道怎么解决吗?以下是我的测试代码:
it('should return correct player',function(done){
var url = '/api/players/' + pid;
request(app)
.get(url)
.expect(200)
.expect(function(res){
res.body.should.have.property('name');
})
.end(done);
});
【问题讨论】: