i'm having trouble with http response in chai tests, i don't know how can i get the length of the res.body unless by console.log.
it's the test i'm trying to run:
it('It should have a length of 3061', function(){
chai.request('http://localhost:8080')
.get('/api/pac/')
.end(function(err,res){
console.log(res.body.length); //it shows 3061
expect(res.body).to.have.lengthOf(3061); //it causes error "Cannot read property 'body' of undefined"
});
});
if i try to do an expect with res.body, it returns "Cannot read property 'body' of undefined". But a console.log works.
A console.log(res.body) shows a json with 3061 objects. Each Object have this structure:
iid : {type : Number},
dnas : [{ _id : Number,
col : Date,
reproved : {type : Boolean},
wave : {type: Number,
index: true}
}],
name : { type : String,
uppercase: true,
index: true}