supertest expect(function(res){}),错误:预期[功能]响应体??

时间:2014-02-27 05:54:03

标签: mocha supertest

我正在使用supertest和mocha测试我的快速休息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);

});

1 个答案:

答案 0 :(得分:2)

在supertest的0.9.0版本中添加了将函数传递给.expect()的功能,该版本目前是最新版本。

这些是有问题的提交:https://github.com/visionmedia/supertest/commit/00dad1bf84896f8a610b028dcbd81ce2e53779fbhttps://github.com/visionmedia/supertest/commit/a8e5596cc94e97e2b937792853c498cae4ca6764

只需更新supertest包即可。

相关问题