【问题标题】:supertest expect(function(res){}) , Error: expected [Function] response body ??supertest expect(function(res){}) ,错误:预期的 [Function] 响应正文??
【发布时间】: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);

});

【问题讨论】:

    标签: mocha.js supertest


    【解决方案1】:

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

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

    只需更新supertest 包,它应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      • 2018-04-08
      • 2021-11-09
      • 1970-01-01
      • 2019-12-06
      • 2022-09-11
      • 1970-01-01
      相关资源
      最近更新 更多