TypeError: expect(...).to.have.length.of is not a function


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)
			.then(function(_res) {
				res = _res;
				return BlogPost.count();
			.then(function(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?


It’s been a while since I’ve used Chai. Does this work?



Is it the exact same error or is length now lengthOf on the error message?


I was wrong, @object88’s solution worked – I was so eager to run it that I didn’t change the following assertion to match. The test is passing now :blush:Thanks for your help!