Trying to write integration tests using Chai. The test I’ve written is supposed to return all existing blog posts from my test DB, prove the response has the correct status, and that the number of posts in the response is equal to the number in the DB. I’m trying to check the length of the response body to be sure that my test DB seeding worked, but I keep getting this error:
TypeError: expect(...).to.have.length.of is not a function
This is the relevant piece of code:
`describe('GET endpoint', function() {
it('should return all existing blog posts', function() {
let res;
return chai.request(app)
.get('/posts')
.then(function(_res) {
res = _res;
expect(res).to.have.status(200);
expect(res.body).to.have.length.of.at.least(1);
return BlogPost.count();
})
.then(function(count) {
expect(res.body).to.have.length.of(count);
})
})`
I tried changing the offending line to res.body.should.have.length.of.at.least(1)
, but that gave me this error: AssertionError: expected { Object (_events, _eventsCount, ...) } to have property 'length'
.
Anyone have any idea why this is happening?