0

I'm using supertest and mocha testing my express rest api. there's this test case I want to check the returned response body with a method of supertest:expect(function(res){ } ). But I'm facing an error that I can't figure out why:

Error: expected [Function] response body, got '{"name":"Aaron Shen","_id":"
530ed1ce92788ed031022d8c","__v":0,"active":true}'

Does anybody know how to fix? below is my testing code:

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

});
Aaron Shen
  • 8,124
  • 10
  • 44
  • 86

1 Answers1

2

The ability to pass a function to .expect() was added in version 0.9.0 of supertest, which as of now is the latest version.

These are the commits in question: https://github.com/visionmedia/supertest/commit/00dad1bf84896f8a610b028dcbd81ce2e53779fb, https://github.com/visionmedia/supertest/commit/a8e5596cc94e97e2b937792853c498cae4ca6764

Just update the supertest package and it should work.